#include<bits/stdc++.h> using namespace std; int x,p,k; long long f(int a,int b){ if(b==0) return 1%k; if(b==1) return a%k; long long ans=f(a,b/2)%k; ans*=ans%k; if(b%2==1) ans*=a%k; return ans%k; } int main(){ cin>>x>>p>>k; f(x,p); cout<<x<<"^"<<p<<" "<<"mod"<<" "<<k<<"="<<f(x,p)%k; return 0; }