[bzoj]1008: [HNOI2008]越狱

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 #define LL long long
 2 
 3 #include<iostream>
 4 using namespace std;
 5 
 6 const LL mod=100003;
 7 LL m,n;
 8 
 9 LL modexp(LL a,LL b)
10 {
11     LL ret=1,tmp=a;
12     while(b)
13     {
14         if(b&1) ret=(ret*tmp)%mod;
15         tmp=(tmp*tmp)%mod;
16         b>>=1;
17     }
18     return ret;
19 }
20 
21 int main()
22 {
23     cin>>m>>n;
24     cout<<(modexp(m,n)-(modexp(m-1,n-1)*m)%mod+mod)%mod;
25     return 0;
26 }

 

posted @ 2016-10-18 20:21  InWILL  阅读(152)  评论(0编辑  收藏  举报