bzoj1008| HNOI2008 Jailbreak

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.