215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?
题目大意:
题目大意:
215 = 32768 并且其各位之和为 is 3 + 2 + 7 + 6 + 8 = 26.
21000 的各位数之和是多少?
// (Problem 16)Power digit sum // Completed on Sun, 17 Nov 2013, 15:23 // Language: C // // 版权所有(C)acutus (mail: acutus@126.com) // 博客地址:http://www.cnblogs.com/acutus/ #include <stdio.h> #include <stdbool.h> void solve(void) { int a[100000] = {0}; int n, sum, i, j; n = sum = 0; a[0] = 1; for(i = 0; i < 1000; i++) { //以1000进制的方法存储 for(j = 0; j <= n; j++) { a[j] *= 2; } for(j = 0; j <= n; j++) { if(a[j] >= 10000) { a[j] %= 10000; a[j+1]++; n++; } } } for(i = 0; i <= n; i++) { sum += a[i] / 10000; a[i] %= 10000; sum += a[i] / 1000; a[i] %= 1000; sum += a[i] / 100; a[i] %= 100; sum += a[i] / 10; a[i] %= 10; sum += a[i]; } printf("%d ",sum); } int main(void) { solve(); return 0; }
Answer:
|
1366 |