## ZOJ3549 Little Keng(快速幂)

Little Keng

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 mn. (1 <= m <= 100 , 1 <= n <= 1000000)

#### Output

One line containing one integer indicatint the number of 0s.

4 3

#### Sample Output

2

 1 /**
2  * code generated by 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 //#####################
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
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);
82     std::istream &in(std::cin);
83     std::ostream &out(std::cout);
84     solver.solve(in, out);
85     return 0;
86 }

posted on 2015-08-16 00:41  xyiyy  阅读(...)  评论(...编辑  收藏

• 随笔 - 102
• 文章 - 0
• 评论 - 7
• 引用 - 0