#include <iostream>
using namespace std;
long long a,b,c,d,e;
long long sum = 1;
void hanshu(){
if(b%2==1){
sum*=a%c;
b--;
b/=2;
a = (a*a)%c;
} else if(b%2==0){
b/=2;
a = (a*a)%c;
}
}
int main(){
cin>>a>>b>>c;
d = a;
e = b;
while(b>1){
hanshu();
}
cout << e << '^' << d << " mod " << c << "=" << sum*a%c;
return 0;
}