1 条题解

  • 1
    @ 2026-9-13 13:22:24
    #include <cmath>
    #include <cstring>
    #include <cstdio>
    
    using namespace std;
    
    const int DIGITS = 500;
    
    void multiply(const int a[DIGITS], const int b[DIGITS], int res[DIGITS]) {
        static int temp[DIGITS + 5];
        memset(temp, 0, sizeof(temp));
        for (int i = 0; i < DIGITS; ++i) {
            if (!a[i]) continue;
            for (int j = 0; j < DIGITS - i; ++j) {
                temp[i + j] += a[i] * b[j];
            }
        }
        for (int i = 0; i < DIGITS; ++i) {
            if (temp[i] >= 10) {
                temp[i + 1] += temp[i] / 10;
                temp[i] %= 10;
            }
            res[i] = temp[i];
        }
    }
    
    int ans[DIGITS];
    int base[DIGITS];
    int tmp[DIGITS];
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    
        int p;
        if (!(cin >> p)) return 0;
    
        int num_digits = (int)floor(p * log10(2.0)) + 1;
        cout << num_digits << "\n";
    
        ans[0] = 1;
        base[0] = 2;
    
        int power = p;
        while (power > 0) {
            if (power & 1) {
                multiply(ans, base, tmp);
                memcpy(ans, tmp, sizeof(ans));
            }
            power >>= 1;
            if (power > 0) {
                multiply(base, base, tmp);
                memcpy(base, tmp, sizeof(base));
            }
        }
    
        ans[0] -= 1;
    
        // Output all 500 digits on a single line
        for (int i = DIGITS - 1; i >= 0; --i) {
            cout << ans[i];
        }
        cout << "\n";
    
        return 0;
    }
    
    
    • 1

    信息

    ID
    666
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    递交数
    76
    已通过
    5
    上传者