code:
#include<bits/stdc++.h>
using namespace std;
int a,b,P;
long long poww(int x,int y){
int ans=1;
while(y){
if(y&1!=0){
ans=(ans*x)%P;
}
x*=x;
y>>=1;
}
return ans;
}
int main(){
cin>>a>>b>>P;;
cout<<a<<"^"<<b<<" mod "<<P<<"="<<poww(a,b);
return 0;
}