51Nod 1003 阶乘后面0的数量 | 思维

题意:n的阶乘后面0的个数,如果直接算出阶乘再数0的数量一定会超时的。
为10=2*5,所以求出5贡献的次数就行。
#include "bits/stdc++.h"
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f3f
#define PI acos(-1)
#define N 510
LL arr[N];
int main()
{
    int n,k;
    while(~scanf("%d",&n)){
        int sum=0;
        while(n>0){
            sum+=n/5;
            n/=5;
        }
        printf("%d
",sum);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/kimsimple/p/7460716.html