1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 using namespace std;
5 long long b,p,k,ans=1,q,t;
6 int main()
7 {
8 scanf("%d%d%d",&b,&p,&k);q=p;t=b;
9 while(p>0)
10 {
11 if(p%2==1) ans=(ans*b)%k;
12 p/=2;
13 b=(b*b)%k;
14 }
15 cout<<t<<'^'<<q<<" mod "<<k<<'='<<ans<<endl;
16 return 0;
17 }