Z(N) is the number of zeros at the end of the decimal form of number N!
求n!中末尾0的个数,转化为n中有几个5.
#include <cstdio>
int main()
{
int n, sum, i, t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(sum=0,i=5;i<=n;i*=5)
sum+=n/i;
printf("%d\n",sum);
}
return 0;
}
本文介绍了一种计算任意正整数阶乘结果中末尾零数量的方法。通过统计阶乘分解中5的倍数个数来快速得出结果。
2895

被折叠的 条评论
为什么被折叠?



