您的位置:首页 > 其它

ECNU_OJ_1008

2016-04-02 23:11 253 查看

Zero

Time Limit:1000MS Memory Limit:30000KB

Total Submit:1470 Accepted:685

Description

A long time ago people found the value zero to be very useful. Just think about the romans and many more nations that didn’t know the zero. Their number representations couldn’t display the zero and that’s why they are dead now.

So you’ve got to understand the overwhelming importance of this beautiful gift of science (or nature ?) and praise the zero. That’s what you’ll do here.

Find out how many trailing zeros are at the end of n! (n factorial). That’s all you have to do, but be careful to write an efficient program, n can be really large. For example,

42! = 1405006117752879898543142606244511569936384000000000

so the answer for n=42 would be 9, since there are nine zeros at the end.

Input

The first line contains an integer m, the number of test cases. After that follow m lines. Every line represents one testcase, which only contains the integer number n. The value of n will be at least 1 and won’t be bigger than 2.000.000.000.

Output

For each testcase, print a line containing the number of trailing zeros. Do not print whitespace before or after the number.

Sample Input

4

1

23

42

2000000000

Sample Output

0

4

9

499999997

Source

Freshman Programming Contest

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
int temp;
int count = 0;
scanf("%d", &temp);
while(temp / 5 != 0)
{
count += temp / 5;
temp /= 5;
}

printf("%d\n", count);
}

system("pause");
return 1;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: