码迷,mamicode.com
首页 > 其他好文 > 详细

[bzoj]1008: [HNOI2008]越狱

时间:2016-10-18 22:19:01      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

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 }

 

[bzoj]1008: [HNOI2008]越狱

标签:

原文地址:http://www.cnblogs.com/InWILL/p/5974772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!