▼页尾

[Project Euler] Problem 20

n! means n × (n − 1) × ... × 3 × 2 × 1

Find the sum of the digits in the number 100!

这道题的做法和那个求2的1000次方的各位和的思路一样

我们只需要在那道题程序的基础上稍加改变就可以了

#include <iostream>
usingnamespace std;

int main(){
int sum[200]={1};
int tmp;
int all=0;
for(int i=1;i<=100;i++){
int carry =0;
for(int j=0;j<200;j++){
tmp
= sum[j]*i;
sum[j]
= (tmp+carry)%10;
carry
= (tmp+carry)/10;
}
}
for(int j=0;j<200;j++){
all
+= sum[j];
}
cout
<< all << endl;
return0;
}

posted @ 2011-03-05 12:34  xiatwhu  阅读(235)  评论(0编辑  收藏  举报
▲页首
西