1950 - 阶乘末尾0的个数
求N!末尾有多少个0?
Input
输入多组数据,每组占一行,每行包括一个正整数N(N<=1000000)
Output
输出N!末尾有多少个0。
Examples
Input
5 100
Output
1 24
Solution C
#include <stdio.h> #include <math.h> int main() { int n; while(scanf("%d",&n)!=EOF) { int sum=0; while(n>=5) { n/=5; sum+=n; } printf("%d\n",sum); } return 0; }
Solution C++
#include<stdio.h> int main() { int a=0,b=0,i,j; while(~scanf("%d",&a)) { for(i=1 ;i<=a;i++) { j=i; while(j%5==0) { b++; j/=5; } } printf("%d\n",b); b=0; } return 0; }