[HNOI 2008]越狱

Description

  监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种。如果
相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱

Input

  输入两个整数M,N.1<=M<=10^8,1<=N<=10^12

Output

  可能越狱的状态数,模100003取余

Sample Input

2 3

Sample Output

6

HINT

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

题解

只有刷水题才能维持生活...酱紫...

 1 //It is made by Awson on 2018.1.13
 2 #include <set>
 3 #include <map>
 4 #include <cmath>
 5 #include <ctime>
 6 #include <queue>
 7 #include <stack>
 8 #include <cstdio>
 9 #include <string>
10 #include <vector>
11 #include <cstdlib>
12 #include <cstring>
13 #include <iostream>
14 #include <algorithm>
15 #define LL long long
16 #define Max(a, b) ((a) > (b) ? (a) : (b))
17 #define Min(a, b) ((a) < (b) ? (a) : (b))
18 #define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
19 using namespace std;
20 const int MOD = 100003;
21 void read(LL &x) {
22     char ch; bool flag = 0;
23     for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
24     for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
25     x *= 1-2*flag;
26 }
27 void write(LL x) {
28     if (x > 9) write(x/10);
29     putchar(x%10+48);
30 }
31 
32 LL n, m;
33 
34 LL quick_pow(LL a, LL b) {
35     b %= MOD-1; a %= MOD; LL ans = 1;
36     while (b) {
37     if (b&1) ans = ans*a%MOD;
38     a = a*a%MOD, b >>= 1;
39     }
40     return ans;
41 }
42 void work() {
43     read(m), read(n);
44     write((quick_pow(m, n)-m*quick_pow(m-1, n-1)%MOD+MOD)%MOD);
45 }
46 int main() {
47     work();
48     return 0;
49 }

 

posted @ 2018-01-13 08:17  NaVi_Awson  阅读(159)  评论(0编辑  收藏  举报