您的位置:首页 > 其它

【bzoj 1008】[HNOI2008]越狱

2017-03-27 19:37 274 查看
[HNOI2008]越狱

Time Limit: 1 Sec Memory Limit: 162 MB

Submit: 8811 Solved: 3812

[Submit][Status][Discuss]

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)

Source

总状态为M^N 不发生越狱的有M*(M-1)^(N-1)

#include<bits/stdc++.h>
using namespace std;
typedef long long ull;
const ull mod = 100003;

ull po(ull a,ull b)
{
ull ret=1;
while(b>0)
{
if(b&1)ret=(ret%mod*a%mod)%mod;
a=(a%mod*a%mod)%mod;
b>>=1;
}
return ret;
}
signed main()
{
ull n,m;
cin>>m>>n;
cout<<(po(m,n)-(m%mod)*(po(m-1,n-1))%mod+mod)%mod;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: