判断N!有多少个零,可用下列公式:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 using namespace std; 5 6 int ZeroTrail(int n) 7 { 8 int count = 0; 9 while(n) 10 { 11 count += n/5; 12 n /= 5; 13 } 14 return count; 15 } 16 17 int main() 18 { 19 int q; 20 cin >> q; 21 if(!q) 22 { 23 cout << 1 << endl; 24 return 0; 25 } 26 27 int i = 4 * q / 5 * 5; 28 while(ZeroTrail(i) < q) 29 i += 5; 30 if(q == ZeroTrail(i)) 31 cout << i << endl; 32 else 33 cout << "No solution" << endl; 34 return 0; 35 }