1000!后有多少个零
1000!后有多少个零
#include<stdio.h> int jsum(int m) { int sum=0; int t=1,s=1; for(;t<=m;t++) { s*=t; while(s %10==0) { sum++; s/=10; } if(s>10000) { s=s-10000*(s/10000); } } return sum; } int jsum2(int m) { int sum=0; while(m>0) { sum+=m/5; m/=5; } return sum; } int main() { for(int i=10;i<=10+1015;i+=35) { printf(" %4d !的后面有连续%3d个〇\n",i,jsum(i)); printf("方法2计算: %4d !的后面有连续%3d个〇\n",i,jsum2(i)); } return 0; }