#include<bits/stdc++.h>
#include <functional>
using namespace std;
long long power(long long a,long long b,long long c){
if(b0){
return 1;
}
int t=power(a,b/2,c);
t=(long long)t*t%c;
if(b%21){
t=(long long)t*a%c;
}
return t;
}
int main(){
long long a,b,c;
cin>>a>>b>>c;
cout<<a<<"^"<<b<<" "<<"mod"<<" "<<c<<"="<<power(a,b,c);
}