1.链接地址

https://vjudge.net/problem/POJ-1401

2.问题描述

 For example, they defined the function Z. For any positive integer N, Z(N) is the number of zeros at the end of the decimal form of number N!. They noticed that this function never decreases. If we have two numbers N1 < N2, then Z(N1) <= Z(N2). It is because we can never "lose" any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program that can determine its value efficiently. 

输入样例

6
3
60
100
1024
23456
8735373

输出样例

0
14
24
253
5861
2183837

3.解题思路

 这道题的思路是从1到n的数中有几个5的倍数,如果是10、20、30等等这些数,因子中只有一个5,所以算一次。如果是25,50,75等等这些数,因子中有5的平方,所以算两次。依此规律,125,625等等同样可以这样算。

4.算法实现源代码

#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int s[20];
int main()
{
    int i,j,n,k,l;
    int ss,ans;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&k);
        ans=0;
        ss=5;
        while(ss<=k)
        {
            ans+=k/ss;
            ss*=5;
        }
        printf("%d\n",ans);
    }
    return 0;
}