Title 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/output format
Input format:
Enter a two integer m,n.1<=m<=10^8,1<=n<=10^12
Output format:
Number of possible jailbreak states, modulo 100003 take-up
Input and Output Sample input example # #:
2 3
Sample # # of output:
6
Description
6 states of (000) (001) (011) (100) (110) (111)
/*the number of jailbreak scenarios is required, and the number of jailbreak programs equals the total number of programs-the total number of non-jailbroken programs is clearly the number of m^n non-jailbreak scenarios: Make any two rooms non-identical religion, then just meet each room and the previous room of the religion is different, so launched s=m* (m-1) * (m-1) * ( m-1) *...* (m-1) [(m-1) has n]=m* (m-1) ^ (n-1); ans=m^n-m* (m-1) ^ (n-1);//Pay attention to a negative number*/#include<cstdio>using namespaceStd;typedefLong Longll;ll N,m,ans,mod=100003ll Fpow (ll A,ll p) {ll res=1; for(;p; p>>=1, A=a*a%mod)if(p&1) res=res*a%MoD; returnRes;}intMain () {scanf ("%lld%lld",&m,&N); Ans= (Fpow (m,n)-m%mod*fpow (M-1, N-1))%MoD; if(ans<0) Ans+=mod;//Wa*nprintf"%lld", ans); return 0;}
P3197 [HNOI2008] Jailbreak