监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种。如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱
标签:des blog http ar io os sp on div
监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种。如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱
输入两个整数M,N.1<=M<=10^8,1<=N<=10^12
可能越狱的状态数,模100003取余
6种状态为(000)(001)(011)(100)(110)(111)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
#define INF 1<<30
#define mod 100003
#define ll long long
using namespace std;
ll m,n;
ll pow(ll a,ll b)
{
ll c=1,d=a%mod;
while (b>0)
{
if (b&1)
c=c*d%mod;
b>>=1;
d=d*d%mod;
}
return c;
}
int main()
{
scanf("%lld%lld",&m,&n);
long long ans=pow(m,n);
ans=ans-m*pow(m-1,n-1)%mod;
if (ans<0) ans+=mod;
printf("%lld\n",ans);
return 0;
}
标签:des blog http ar io os sp on div
原文地址:http://www.cnblogs.com/a972290869/p/4170864.html