Bzoj a rare water problem
1008: [HNOI2008] Jailbreak time limit: 1 Sec Memory Limit: 162 MB
Submit: 4977 Solved: 2149
[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]
/* ***********************************************author : ckbosscreated time : Saturday May 09, 2015 16:24 47 sec File Name : bzoj1008.cpp************************************************ */#include <iostream># Include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath > #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> Using namespace std;typedef long long int ll;const LL mod=100003; LL M,n; ll Quickpow (ll a,ll N) {ll e=1ll;while (n) {if (n&1) e= (a*e)%mod;a= (a*a)%mod;n=n>>1;} return e%mod;} int main () { //freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout); scanf ("%lld%lld", &m,&n); LL ans= (Quickpow (m,n) +mod-(M*quickpow (m-1,n-1))%mod)%mod;printf ("%lld\n", ans); return 0;}
Bzoj 1008: [HNOI2008] Jailbreak water