#include
using namespace std;
unsigned long long int sum ;
void fast(unsigned long long int x, unsigned long long int y, unsigned long long int c) {
sum = 1;
x = x%c;
while (y) {
//if y is odd
if (y & 1) sum = sum*x%c;
y >>= 1;
x = x*x%c;
}
}
int main() {
long long int x, y, c;
while (scanf_s("%lld%lld%lld",&x,&y,&c)!=EOF) {
fast(x, y, c);
cout << sum << endl;
}
}