#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll fastpow(ll a,ll n,ll m){
if(n==0) return 1;
if(n==1) return a;
ll temp=fastpow(a,n/2,m);
if(n&1) return temp*temp*a%m;
else return temp*temp%m;
}
int main(){
ll a,n,m;
cin>>a>>n>>m;
ll N=n;
cout<<a<<"^"<<N<<" "<<"mod"<<" "<<m<<"="<<fastpow(a,n,m);
return 0;
}