欧拉计划第16题题解

Power digit sum

\(2^{15} = 32768\) and the sum of its digits is \(3 + 2 + 7 + 6 + 8 = 26\).

What is the sum of the digits of the number \(2^{1000}\)?

幂的数字和

\(2^{15} = 32768\),而 \(32768\) 的各位数字之和是 \(3 + 2 + 7 + 6 + 8 = 26\)

\(2^{1000}\) 的各位数字之和是多少?

解题思路

没有比较好的想法。目前的想法是高精度模拟。

实现代码如下:

#include <bits/stdc++.h>
using namespace std;
int a[500], n = 1, ans;
int main() {
    a[0] = 1;
    for (int i = 0; i < 1000; i ++) {
        for (int j = 0; j < n; j ++) a[j] *= 2;
        for (int j = 0; j < n; j ++) {
            a[j+1] += a[j]/10;
            a[j] %= 10;
        }
        if (a[n]) n ++;
    }
    for (int i = n-1; i >= 0; i --) {
//        cout << a[i];
        ans += a[i];
    }
//    cout << endl;
    cout << ans << endl;
    return 0;
}

答案为 \(1366\)

posted @ 2020-02-18 21:15  quanjun  阅读(231)  评论(0编辑  收藏  举报