51nod1003 阶乘后面0的数量

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相声乘才一个0,n的阶乘就是求2和5的对数,由于n!中2的的因子数大于5,其实就是求5的因子数有多少。
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #define ll long long
 6 using namespace std;
 7 int main() {
 8     int n, ans = 0;
 9     cin >> n;
10     while(n) {
11         ans += n/5;
12         n/=5;
13     }
14     cout << ans << endl;
15     return 0;
16 }
原文地址:https://www.cnblogs.com/xingkongyihao/p/7308649.html