分析:
要想尾数为0,那么必然包含2和5两个因子,而n!的因式分解中,2的因子个数肯定要大于5的因子个数,因此我们只要统计5这个因子即可。
由性质可知:n!在素数因子分解中的素数p的幂为[n/p] + [n/p^2] + [n/p^3] + ......
代码如下:
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int ans = 0;
int cnt = 5;
while(n)
{
ans += n/cnt;
n/=cnt;
}
printf("%d\n",ans);
}
return 0;
}