求N! 中0 的个数 参考别人的。 因子分解 分析如下: 只有2*5 才会有10,也就是0出现。 也就是求N中有多少个被5整除的数。 然后更新N=N/5;接着求。最后的总数就是0的个数,
代码:
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int t;
scanf(
"%d",&t);
int n;
int ans;
while(t--){
ans=
0;
scanf(
"%d",&n);
while(n){
ans+=n/
5;
n/=
5;
}
printf(
"%d\n",ans);
}
return 0;
}
转载请注明原文地址: https://www.6miu.com/read-57247.html