#include <bits/stdc++.h>
#define int long long
using namespace std;
int a, b, p;
int fast_pow(int x, int y){
if (y == 1)
return x;
if (y % 2 == 1)
return (fast_pow(x, y / 2) % p * fast_pow(x, y / 2) % p) * x % p;
else
return (fast_pow(x, y / 2) % p * fast_pow(x, y / 2) % p) % p;
}
main(){
cin >> a >> b >> p;
cout << a << '^' << b << " mod " << p << '=' << fast_pow(a, b);
return 0;
}