#include <iostream> # define LL long long using namespace std; LL b; LL p,k; int main(){ scanf("%lld%lld%lld", &b, &p, &k); LL d=p; LL ans=1; LL base=b; while(p>0){ if(p&1){ ans*=base; ans%=k; } base*=base; base%=k; p>>=1; } printf("%lld^%lld mod %lld=%lld", b,d,k,ans%k); return 0; }