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的倍数出现次数来确定零的数量。提供了一个C语言程序示例,演示了如何实现这一计算过程。
2906

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



