#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 40000 + 20;
const int moder = 1e9 + 7;
const int K = 256;
ll mod_pow(ll x,ll n,ll mod)
{
ll res = 1;
while(n > 0)
{
if(n & 1) res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
int main()
{
ll b,p,k;
scanf("%lld%lld%lld",&b,&p,&k);
cout << b << "^" << p << " " << "mod " << k <<"=" <<mod_pow(b,p,k);
return 0;
}