1 条题解

  • 1
    @ 2026-8-30 20:16:43
    #include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    
    int main() {
        int N, R;
        cin >> N >> R;
        R = -R;
        if (N == 0) {
            cout << 0 << "=" << 0 << "(base" << -R << ")" << endl;
            return 0;
        }
        vector<int> digits;
        int n = N;
        while (n != 0) {
            int r = n % R;
            if (r < 0) r += R;
            n = (n - r) / (-R);
            digits.push_back(r);
        }
        reverse(digits.begin(), digits.end());
        cout << N << "=";
        for (int d : digits) {
            if (d < 10) cout << d;
            else cout << (char)('A' + d - 10);
        }
        cout << "(base" << -R << ")" << endl;
        return 0;
    }
    
    
    

    信息

    ID
    1209
    时间
    1000ms
    内存
    128MiB
    难度
    7
    标签
    递交数
    26
    已通过
    7
    上传者