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,但是2会远远多于5,所以只要考虑5出现多少 次就行了 ,对于n!来说,5出现 的次数就是(n/5+n/25+n/125+…….)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
int temp=5;
int sum=0;
while(temp<=n)
{
sum+=(n/temp);
temp*=5;
}
cout<<sum<<endl;
}
}