hdu 5187 zhx's contest
zhx's contest
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<algorithm> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdio> 5 #include<cmath> 6 using namespace std; 7 #define LL long long 8 LL n,m,p,tot; 9 10 LL qcheng(LL a,LL b,LL p) 11 { 12 LL base=0,res=a; 13 while(b) 14 { 15 if(b&1) base=(base+res)%p; 16 res=(res+res)%p; b>>=1; 17 } 18 return base; 19 } 20 21 LL qpow(LL a,LL b,LL mod) 22 { 23 LL res=a%mod,base=1; 24 while(b) 25 { 26 if(b&1) base=qcheng(base,res,mod); 27 res=qcheng(res,res,mod); 28 b>>=1; 29 } 30 return base; 31 } 32 33 int main() 34 { 35 // freopen("permutation.in","r",stdin); 36 // freopen("permutation.out","w",stdout); 37 while(scanf("%lld%lld",&n,&p)!=EOF) 38 { 39 tot=0; 40 if(n==1) 41 { 42 printf("0\n"); 43 continue ; 44 } 45 else { 46 LL ans=(qpow(2,n-1,p)-1+p)%p*2%p; 47 if(ans<0) ans+=p; 48 printf("%lld\n",ans); 49 } 50 } 51 return 0; 52 }