https://www.acwing.com/problem/content/91/
#include<bits/stdc++.h>
using namespace std;
int a,b,p;
long long int fastPower(long long int base, long long int power) {
long long int res = 1;
while (power > 0) {
if (power & 1) {
res = res * base % p;
}
power >>= 1;
base = (base * base) % p;
}
return res;
}
int main(){
cin>>a>>b>>p;
cout<<fastPower(a,b)%p;
return 0;
}