bzoj1008 Math problem + fast power

Source: Internet
Author: User

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #defineRep (i,l,r) for (int i=l;i<r;i++)6 #defineCLR (a,x) memset (A,x,sizeof (a))7 #defineINF 1000038 using namespacestd;9typedefLong Longll;Ten ll N,m; One intMain () A { -Cin>>m>>N; -ll sum=m,ans=m,f=m,k=m-1; the--N; -      while(n) -     { -         if(n&1){ +(sum*=f)%=inf; -(ans*=k)%=inf; +         } A(k*=k)%=inf; at(f*=f)%=inf; -n>>=1; -     } -printf"%lld", (Sum-ans+inf)%inf); -     return 0; -}
View Code 1008: [HNOI2008] Jailbreak time limit:1 Sec Memory limit:162 MB
submit:5135 solved:2226
[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]

bzoj1008 Math problem + fast power

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.