标签:cat one any second similar sub tle hint sep
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3568 Accepted Submission(s): 1146
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,p;
ll multi(ll a,ll b){
ll res=0,tmp=a;
while(b){
if(b&1) (res+=tmp)%=p;
b/=2;
(tmp+=tmp)%=p;
}
return res;
}
ll pow_(ll a,ll b){
ll res=1,tmp=a;
while(b){
if(b&1) res=multi(res,tmp);
tmp=multi(tmp,tmp);
b/=2;
}
return res;
}
int main(){
while(cin>>n>>p){
ll ans=pow_(2,n);
ans-=2;
ans=(ans%p+p)%p;
cout<<ans<<endl;
}
return 0;
}
标签:cat one any second similar sub tle hint sep
原文地址:https://www.cnblogs.com/vainglory/p/9201749.html