51 Nod 阶乘后面0的数量

1003 阶乘后面0的数量 

基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题

 收藏

 关注

n的阶乘后面有多少个0?

6的阶乘 = 1*2*3*4*5*6 = 720,720后面有1个0。

Input

一个数N(1 <= N <= 10^9)

Output

输出0的数量

Input示例

5

Output示例

1

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

int main()
{
    int total=0;
    int N;
    cin>>N;
    int sum=1;
    while(sum*5<=N){sum*=5;total++;}
    int fac=5;
    ll ans=0;
    for(int i=0;i<total;i++)
    {
        ans+=(N/fac);
        fac*=5;
    }
    cout<<ans<<endl;
    return 0;
}
 

 

posted @ 2018-07-18 19:24  erge1998  阅读(123)  评论(0编辑  收藏  举报