基准时间限制: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
其实只要循环除五就可以找到规律,其实也可以证明出来。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #define N 504 5 #define mem(a) memset(a,0,sizeof(a)) 6 using namespace std; 7 int main(){ 8 int n; 9 scanf("%d",&n); 10 int a=0; 11 while(n){ 12 a+=n/5; 13 n=n/5; 14 } 15 16 cout<<a<<endl; 17 return 0; 18 }