[Project Euler] Problem 16
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?
#include <iostream>
using namespace std;
int main(){
int sum[330]={1};
int tmp;
int all=0;
for(int i=0;i<1000;i++){
int carry = 0;
for(int j=0;j<330;j++){
tmp = sum[j]*2;
sum[j] = tmp%10+carry;
carry = tmp/10;
}
}
for(int j=0;j<330;j++){
all += sum[j];
}
cout << all << endl;
return 0;
}
这道题没什么好讲的,直接计算,大数用数组表示