1 #include<iostream> 2 using namespace std; 3 long long f(int x,int p,int mod) 4 { 5 int now=1; 6 while(p) 7 { 8 if(p & 1) 9 now=now * x % mod; 10 x=x*x%mod; 11 p=p>>1; 12 } 13 return now; 14 } 15 int main() 16 { 17 int x,p,mod; 18 cin>>x>>p>>mod; 19 cout<<f(x,p,mod); 20 return 0; 21 }