#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long b,p,k;
long long pow(long long a,long long b){
long long s=1;
for(;b;b>>=1){
if(b&1) s=s*a%k;
a=a*a%k;
}
return s;
}
int main(){
scanf("%lld%lld%lld",&b,&p,&k);
printf("%lld^%lld mod %lld=%lld",b,p,k,pow(b,p));
}