#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, p;
cin >> a >> b >> p;
cout << a << '^' << b << " mod " << p << '=';
if (p == 1) {
cout << 0;
return 0;
}
int r = 1;
while (b != 0) {
if (b & 1 == 1)
r = r*a%p;
a = a * a;
b = b >> 1;
}
cout << r % p;
return 0;
}