阶乘 - 求末尾0个数
题目地址:http://www.51cpc.com/web/problem.php?id=1581
Summarize:
1. 实质:计算5的个数(25 = 5*5,以此类推)
2. 层次累加计算
3. 数据范围
1 #include<iostream> 2 using namespace std; 3 #define LL long long 4 5 int n; 6 int main() 7 { 8 ios::sync_with_stdio(false); 9 10 while(cin>>n) 11 { 12 LL ans=0; 13 for(int i=5; i<=n; i+=5) { 14 int k=i, t=0; 15 while(!(k%5)) { 16 k/=5; 17 t++; 18 } 19 ans += (n-i+1)*t; 20 } 21 cout<<ans<<endl; 22 } 23 24 return 0; 25 }