# bzoj1008 [HNOI2008]越狱

## 1008: [HNOI2008]越狱

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 5099  Solved: 2207

2 3

6

## HINT

6种状态为(000)(001)(011)(100)(110)(111)

## Source

 1 #include <cstdio>
2 #include <cstring>
3 #include <cstdlib>
4 #include <cmath>
5 #include <deque>
6 #include <vector>
7 #include <queue>
8 #include <iostream>
9 #include <algorithm>
10 #include <map>
11 #include <set>
12 #include <ctime>
13 using namespace std;
14 typedef long long LL;
15 typedef double DB;
16 #define For(i, s, t) for(int i = (s); i <= (t); i++)
17 #define Ford(i, s, t) for(int i = (s); i >= (t); i--)
18 #define MIT (2147483647)
19 #define INF (1000000001)
20 #define MLL (1000000000000000001LL)
21 #define sz(x) ((bnt) (x).size())
22 #define clr(x, y) memset(x, y, sizeof(x))
23 #define puf push_front
24 #define pub push_back
25 #define pof pop_front
26 #define pob pop_back
27 #define ft first
28 #define sd second
29 #define mk make_pair
30 inline void SetIO(string Name) {
31     string Input = Name+".in",
32     Output = Name+".out";
33     freopen(Input.c_str(), "r", stdin),
34     freopen(Output.c_str(), "w", stdout);
35 }
36
37 const LL Mod = 100003;
38 LL N, M;
39 LL All, Impossible, Possible;
40
41 inline void Input() {
42     cin>>M>>N;
43 }
44
45 inline void Multiply(LL &A, LL B) {
46     A = (A*B)%Mod;
47 }
48
49 inline LL Power(LL Basic, LL Tim) {
50     LL Ret = 1;
51     Basic %= Mod;
52     while(Tim) {
53         if(Tim&1) Multiply(Ret, Basic);
54         Multiply(Basic, Basic), Tim >>= 1;
55     }
56     return Ret;
57 }
58
59 inline void Solve() {
60     if(N == 1) {
61         cout<<M<<endl;
62         return;
63     }
64
65     All = Power(M, N);
66     Impossible = Power(M-1, N-1);
67     Multiply(Impossible, M);
68     Possible = All-Impossible;
69     Possible = ((Possible%Mod)+Mod)%Mod;
70
71     cout<<Possible<<endl;
72 }
73
74 int main() {
75     SetIO("1008");
76     Input();
77     Solve();
78     return 0;
79 }
View Code

posted @ 2015-06-20 12:03  yanzx6  阅读(143)  评论(0编辑  收藏