1008: [HNOI2008] Jailbreak time limit:1 Sec Memory limit:162 MB
submit:5166 solved:2242
[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
The problem: Finally caught a flood!
All possible religious options are: m^n
The plan for the impossibility of jailbreaking (the religious beliefs of people in two adjoining rooms) is: m* (M-1) ^ (N-1)
So the final answer: [m^n-m* (M-1) ^ (N-1)]%100003
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Long LongMod=100003; One Long LongPowLong LongXLong Longy) { A Long Longans=1; for(Long Longi=y;i;i>>=1, X=x*x%mod)if(i&1) Ans=ans*x%mod;returnans%MoD; - } -InlineLong LongRead () { the Long Longx=0, sig=1;CharCh=GetChar (); - while(!isdigit (CH)) {if(ch=='-') sig=-1; ch=GetChar ();} - while(IsDigit (CH)) x=Ten*x+ch-'0', ch=GetChar (); - returnx*=Sig; + } -InlinevoidWriteLong Longx) { + if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; A intlen=0;Long Longbuf[ -]; while(x) buf[len++]=x%Ten, x/=Ten; at for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } - Long Longn,m; - voidinit () { -M=read (); n=read (); - Long Longans=Pow (m,n); inAns= (Ans+mod-m*pow (M-1, N-1)%mod)%MoD; - write (ans); to return; + } - voidWork () { the return; * } $ voidprint () {Panax Notoginseng return; - } the intMain () { +Init (); work ();p rint ();return 0; A}
Bzoj 1008 [HNOI2008] Jailbreak