基准时间限制:1 秒 空间限制:131072 KB
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个数就好了; #include <cstdio> typedef long long LL; LL min(LL a, LL b) { return a<b? a:b; } LL cnt_0(LL n) { LL sum=0; int p =10; for(int i=1; i<=10; i++) { sum+= n/p; p*=10; } return sum; } LL cnt_2(LL n) { LL cnt=0; while(n) { cnt+= n/2; n/=2; } return cnt; } LL cnt_5(LL n) { LL cnt=0; while(n) { cnt+= n/5; n/= 5; } return cnt; } int main() { LL n; while(scanf("%lld", &n) != EOF) { printf("%lld ", min(cnt_2(n), cnt_5(n))); } return 0; }