Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define gc c=getchar()
- #define r(x) read(x)
- #define ll long long
- template<typename T>
- inline void read(T&x){
- x=0;T k=1;char gc;
- while(!isdigit(c)){if(c=='-')k=-1;gc;}
- while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
- }
- inline ll qpow(ll a,ll b,int p){
- a%=p;
- ll ans=1;
- while(b){
- if(b&1)(ans*=a)%=p;
- (a*=a)%=p;
- b>>=1;
- }
- return ans;
- }
- inline int sub(ll a,ll b,int p){
- a=(a-b)%p;
- return a<0?a+p:a;
- }
- int main(){
- // freopen(".in","r",stdin);
- // freopen(".out","w",stdout);
- ll n,k,p;r(n),r(k),r(p);
- if(p==2){
- printf("%d\n",k==0);
- return 0;
- }
- printf("%d\n",sub(qpow(2,sub(qpow(2,n,p-1),n,p-1),p),k==0,p));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement