#include <bits/stdc++.h> using namespace std; using ll = long long ; ll euler(ll n){ ll k=n; for(ll i=2;i*i<=n;i++) if(n%i==0){ k-=k/i; while(n%i==0)n/=i; } if(n>1)k-=k/n; return k; } ll mi(ll a,ll b,ll mod){ ll r=1; while(b){ if(1&b)r=r*a%mod; a=a*a%mod; b>>=1; } return r; } int main() { ios::sync_with_stdio(false); string n; ll x,mod; cin>>x>>n>>mod; ll mod1=euler(mod); ll r=0; for(auto t:n) r=(r*10+t-'0')%mod1; r=(r+mod1-1)%mod1; cout<<mi(x,r,mod)%mod; }View Code