ECNU_OJ_1008

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值