n!后面有多少个0
Time Limit 1000ms
Memory Limit 65536K
description |
从输入中读取一个数n,求出n!中末尾0的个数。
|
input |
输入有若干行。第一行上有一个整数m,指明接下来的数字的个数。然后是m行,每一行包含一个确定的正整数n,1<=n<=1000000000。
|
output |
对输入行中的每一个数据n,输出一行,其内容是n!中末尾0的个数。
|
sample_input |
3
3
100
1024
|
sample_output |
0
24
253 |
直接套公式,注意到2的因子数要比5多,所以算5就行。
完整代码:
/*1ms,696KB*/
#include <cstdio>
using namespace std;
int main(void)
{
int n, m;
scanf("%d", &m);
while (m--)
{
scanf("%d", &n);
int t = 5, cnt = 0;
while (t <= n)
{
cnt += n / t;
t *= 5;
}
printf("%d\n", cnt);
}
return 0;
}