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 Input
2 3
Sample Output
6
6 states of (000) (001) (011) (100) (110) (111)
Analysis: This question examines the combinatorial mathematics, the relative normal number topic really sends the cent. The total number of States is m*n, we are not good at statistics can jailbreak the situation, but can easily statistics not jailbreak situation. The first person can choose the religion arbitrarily, then each person behind (N-1) can choose (M-1) religion. Then the number of non-jailbroken cases is m* (M-1) * (N-1).
#include <iostream>
#include <cstdio>
using namespace Std;
Long Long d=100003ll;
Long Long (long X,long long y)
{
Long Long now=1ll,c=x;
while (y)
{
if (y&1) now= (now*c)%d;
C= (c*c)%d;
y=y>>1;
}
return now;
}
int main ()
{
Long Long n,m;
CIN >> m >> N;
M%=d;
Long Long Ans1=pow (m,n)%d;
Long Long ans2= (POW (m-1,n-1) * (m%d))%d;
Long Long ans= (((ans1-ans2+d)%d);//+d anti-negative
return 0;
}
bzoj1008| HNOI2008 Jailbreak