n!末尾零的个数 = [n/5]+[n/25]+[n/125]+.... [x]表示取整
而[n/5^(x+1)]=[[n/5^x]/5]
所以计算后一项直接拿前一项除以5取整就可以了
实际上找因子5的个数就可以了,但如果穷举的话会TLE
Code
#include<iostream>
using namespace std;
int main()
{
int t,n,i,k=0,d=1,q;
cin>>t;
for(i=0;i<t;i++)
{
k=0;
cin>>n;
while(n>=5){
q=n;
while(q>=5)
{
if(q%5==0)
{k++;q/=5;}
else
break;
}
n--;
}
cout<<k<<endl;
}
}