ECNU_OJ_1008

来源:互联网 发布:js中的延时函数 编辑:程序博客网 时间:2024/06/05 03:51

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;}
0 0
原创粉丝点击