基准时间限制:
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
0的产生之和 2 * 5 有关,因此求出1 - N 所有数的2 , 5 因子个数,取最小值。 5 应该比 2 少,因此只算5 就行了。
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
while( ~scanf("%d",&n) ){
int num5 = 0 ;
int num2 = 0 ;
int temp = n;
while( temp ){
num5 += temp/5;
temp /= 5;
}
temp = n;
while( temp ){
num2 += temp/2;
temp /= 2;
}
cout<<min(num5,num2)<<endl;;
}
return 0;
}