计算N!末尾有多少个0,也就是计算有多少个2*5;不同类型的的2*5下产生的0的个数不同,拿1000来说,2的个数总是比5多,故只看5;
每个5个产生一个零(5*2),每个25个产生2个0(25*4);每个125个产生3个0(125*8),所以程序代码为:
#include <iostream>
using namespace std;
int main()
{
int n=0,N;
int five=5;
while(cin>>N){
while(N>five)
{
n+=N/five;
five*=5;
}
cout<<n<<endl;
n=0;
five=5;
}
return 0;
}