1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define rep(i,l,r) for(int i=l;i<r;i++) 6 #define clr(a,x) memset(a,x,sizeof(a)) 7 #define inf 100003 8 using namespace std; 9 typedef long long ll; 10 ll n,m; 11 int main() 12 { 13 cin>>m>>n; 14 ll sum=m,ans=m,f=m,k=m-1; 15 --n; 16 while(n) 17 { 18 if(n&1){ 19 (sum*=f)%=inf; 20 (ans*=k)%=inf; 21 } 22 (k*=k)%=inf; 23 (f*=f)%=inf; 24 n>>=1; 25 } 26 printf("%lld",(sum-ans+inf)%inf); 27 return 0; 28 }
1008: [HNOI2008]越狱
Time Limit: 1 Sec Memory Limit: 162 MB
Submit: 5135 Solved: 2226
[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
时间: 2024-12-14 04:21:16