#include<bits/stdc++.h>
#define pb push_back
#define maxx 1000
using namespace std;
long long powerM(long long b,long long p,long long m)
{
if(p==0)return 1;
long long temp=powerM(b,p/2,m);
temp=(temp%m*temp%m)%m;
if(p%2==0)return temp%m;
else
return ((b%m)*(temp%m))%m;
}
int main() {
long long B,P,M;
while(scanf("%lld %lld %lld",&B,&P,&M)!=EOF)
{
long long ans=powerM(B,P,M)%M;
printf("%lld\n",ans);
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBtYXh4IDEwMDAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKbG9uZyBsb25nIHBvd2VyTShsb25nIGxvbmcgYixsb25nIGxvbmcgcCxsb25nIGxvbmcgbSkKewogICAgaWYocD09MClyZXR1cm4gMTsKICAgIGxvbmcgbG9uZyB0ZW1wPXBvd2VyTShiLHAvMixtKTsKICAgIHRlbXA9KHRlbXAlbSp0ZW1wJW0pJW07CiAgICBpZihwJTI9PTApcmV0dXJuIHRlbXAlbTsKICAgIGVsc2UKICAgICAgICByZXR1cm4gKChiJW0pKih0ZW1wJW0pKSVtOwp9CmludCBtYWluKCkgewogICAgbG9uZyBsb25nIEIsUCxNOwogICAgd2hpbGUoc2NhbmYoIiVsbGQgJWxsZCAlbGxkIiwmQiwmUCwmTSkhPUVPRikKICAgIHsKICAgICAgICBsb25nIGxvbmcgYW5zPXBvd2VyTShCLFAsTSklTTsKICAgICAgICBwcmludGYoIiVsbGRcbiIsYW5zKTsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==