转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Calculate how many 0s at the end of the value below:
1n + 2n + 3n + ... + mn
Input
There are multiple cases. For each cases, the input containing two integers m, n. (1 <= m <= 100 , 1 <= n <= 1000000)
Output
One line containing one integer indicatint the number of 0s.
Sample Input
4 3
Sample Output
2
看完这题,感觉0的位数不会很多,拿Java大数跑了一部分数据,发现就直接取1e9没什么问题,然后就直接搞了。
1 /** 2 * code generated by JHelper 3 * More info: https://github.com/AlexeyDmitriev/JHelper 4 * @author xyiyy @https://github.com/xyiyy 5 */ 6 7 #include <iostream> 8 #include <fstream> 9 10 //##################### 11 //Author:fraud 12 //Blog: http://www.cnblogs.com/fraud/ 13 //##################### 14 //#pragma comment(linker, "/STACK:102400000,102400000") 15 #include <iostream> 16 #include <sstream> 17 #include <ios> 18 #include <iomanip> 19 #include <functional> 20 #include <algorithm> 21 #include <vector> 22 #include <string> 23 #include <list> 24 #include <queue> 25 #include <deque> 26 #include <stack> 27 #include <set> 28 #include <map> 29 #include <cstdio> 30 #include <cstdlib> 31 #include <cmath> 32 #include <cstring> 33 #include <climits> 34 #include <cctype> 35 36 using namespace std; 37 #define rep2(X, L, R) for(int X=L;X<=R;X++) 38 typedef long long ll; 39 40 // 41 // Created by xyiyy on 2015/8/5. 42 // 43 44 #ifndef ICPC_QUICK_POWER_HPP 45 #define ICPC_QUICK_POWER_HPP 46 typedef long long ll; 47 48 ll quick_power(ll n, ll m, ll mod) { 49 ll ret = 1; 50 while (m) { 51 if (m & 1) ret = ret * n % mod; 52 n = n * n % mod; 53 m >>= 1; 54 } 55 return ret; 56 } 57 58 #endif //ICPC_QUICK_POWER_HPP 59 60 class TaskA { 61 public: 62 void solve(std::istream &in, std::ostream &out) { 63 int m, n; 64 while (in >> m >> n) { 65 ll ans = 0; 66 rep2(i, 1, m)ans += quick_power(i, n, 1e9); 67 int cnt = 0; 68 while (ans) { 69 if (ans % 10 != 0)break; 70 cnt++; 71 ans /= 10; 72 } 73 out << cnt << endl; 74 } 75 } 76 }; 77 78 int main() { 79 std::ios::sync_with_stdio(false); 80 std::cin.tie(0); 81 TaskA solver; 82 std::istream &in(std::cin); 83 std::ostream &out(std::cout); 84 solver.solve(in, out); 85 return 0; 86 }