#include<bits/stdc++.h>usingnamespace std;constint maxn =1005;typedeflonglong ll;
ll b, p, k;//底数,指数,模数
ll qpower(ll b, ll n){
ll ans =1;while(n >0){if(n &1)
ans = ans * b;
b = b * b;
n >>=1;}return ans;}
ll qpowermod(ll b, ll n, ll k){
ll ans =1;while(n >0){if(n &1)
ans = ans * b % k;
b = b * b % k;
n >>=1;}return ans % k;}intmain(){#ifdef LOCALfreopen("E:\\Cpp\\1.in","r",stdin);#endifscanf("%lld%lld%lld",&b,&p,&k);printf("%lld^%lld mod %lld=%lld", b, p, k,qpowermod(b, p, k));}