//n!末尾有几个零
#include<stdio.h>
int main()
{
int n,s;
int sum=0;
printf("Input n:");
scanf("%d",&n);
while(n)
{
s=n/5;
sum+=s;
n/=5;
}
printf("%d\n",sum);
return 0;
}
注释:2是足够的关键看有几个5,以100为例,先除以5,除尽的有5,10,15,20,……100等20个数,
得到1,2……20;再除以5,除尽的有5,10,15,20这4个数;于是共24个5,即24个0
另解:5**(m+1)>100,5**(m-1)<100,结果为{n/5+n/(5**2)+n/(5**3)+……+n/(5**m)}