#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int bigMod(int b, int p, int m)
{
int a;
if(p==0) return 1;
if(p%2==0)
{
a = bigMod(b, p/2, m);
return (a*a)%m;
}
else
{
a = bigMod(b, p-1, m)*(b%m);
return a%m;
}
}
int main()
{
int b, p ,m ;
while(scanf("%d %d %d", &b, &p, &m)!=EOF)
{
printf("%d\n", bigMod(b, p, m));
}
return 0;
}
#include<cstdio>
#include<cmath>
using namespace std;
int bigMod(int b, int p, int m)
{
int a;
if(p==0) return 1;
if(p%2==0)
{
a = bigMod(b, p/2, m);
return (a*a)%m;
}
else
{
a = bigMod(b, p-1, m)*(b%m);
return a%m;
}
}
int main()
{
int b, p ,m ;
while(scanf("%d %d %d", &b, &p, &m)!=EOF)
{
printf("%d\n", bigMod(b, p, m));
}
return 0;
}