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