【因子5的个数】1003 阶乘后面0的数量【51nod】

来源:互联网 发布:山西省网络快报系统 编辑:程序博客网 时间:2024/06/01 09:41

题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1003

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<iostream>using namespace std;const int N=100100;int a[N];int b[N];int main(){    int n;    cin.sync_with_stdio(false);    while(cin>>n){        int cnt=0;        while(n){            cnt+=n/5;            n/=5;        }        cout<<cnt<<endl;    }    return 0;}/*    计算因子5的个数;    我们知道,每隔5个数,就有一个5,    例如,5,10,15,20,25,    我们可以发现,其中再每隔5个,又多一个5,所以类推;*/


0 0