1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #defineRep (i,l,r) for (int i=l;i<r;i++)6 #defineCLR (a,x) memset (A,x,sizeof (a))7 #defineINF 1000038 using namespacestd;9typedefLong Longll;Ten ll N,m; One intMain () A { -Cin>>m>>N; -ll sum=m,ans=m,f=m,k=m-1; the--N; - while(n) - { - if(n&1){ +(sum*=f)%=inf; -(ans*=k)%=inf; + } A(k*=k)%=inf; at(f*=f)%=inf; -n>>=1; - } -printf"%lld", (Sum-ans+inf)%inf); - return 0; -}
View Code 1008: [HNOI2008] Jailbreak time limit:1 Sec Memory limit:162 MB
submit:5135 solved:2226
[Submit] [Status] [Discuss] Description
The prison has consecutively numbered 1 ... n rooms of N, one prisoner in each room, a religion of M, and every prisoner may believe in one. If the inmates of the adjoining room are of the same religion, a jailbreak may occur, begging for the number of possible escapes
Input
Enter a two integer m,n.1<=m<=10^8,1<=n<=10^12
Output
Number of possible jailbreak states, modulo 100003 take-up
Sample Input2 3Sample Output6HINT
6 states of (000) (001) (011) (100) (110) (111)
Source [Submit] [Status] [Discuss]
bzoj1008 Math problem + fast power