#include <bits/stdc++.h>
using namespace std;
int quickpower(int a,int b)
{
int ans = 1,base = a;
while(b>0)
{
if(b&1)
{
ans *= base;
}
base*=base;
b>>=1;
}
return ans;
}
int main()
{
unsigned long long a,b,p;
cin>>a>>b>>p;
printf("%lu^%lu mod %lu=%lu",a,b,p,quickpower(a,b)%p);
return 0;
}