P3197 [HNOI2008] Jailbreak

Source: Internet
Author: User

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

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.