Tongji Online Judge
Problem 1011: 阶乘末尾非零数求和
#include"stdio.h"
#include"math.h"
#define mask_5(s) ((s<100000)?s:s%100000)
#define mask_6(s) ((s<1000000)?s:s%1000000)
int main()
{
unsigned int i, j, k, n, num;
unsigned long sum, sum_every, temp, total;
while(scanf("%d", &n)!=EOF) {
sum=1;
total=0;
for(i=1; i<=n; i++){
sum_every=0;
k=i;
while(k%10==0) k/=10;
while(k!=0) {
num=k%10;
k/=10;
sum_every+=sum*num;
if(sum_every%10==0) sum_every/=10;
else break;
}
for(j=1; k!=0; j++) {
num=k%10;
k/=10;
temp=mask_5(sum*num);
sum_every+=temp*(int)pow(10, j);
}
while(sum_every%10==0) sum_every/=10;
sum=mask_6(sum_every);
total+=sum%10;
}
printf("%ld/n", total);
}
return 0;
}