51nod1003 阶乘后面0的数量

来源:互联网 发布:js获取网页源代码 编辑:程序博客网 时间:2024/05/16 02:36
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

//2的个数一定比5要多,所以找出所有的5即可#include<cstdio>#include<iostream>using namespace std;int n;int main(){cin>>n;int ans=0;while(n>0)ans+=n/5,n/=5;cout<<ans<<endl;return 0;}