#include<bits/stdc++.h> using namespace std; #define int long long int a,b,c; signed main(){ cin>>a>>b>>c; int e=1; cout<<a<<"^"<<b<<" mod "<<c<<"="; while(b>0){ if(b%2==1) e=(e*a)%c; a=(a*a)%c; b/=2; } cout<<e; return 0; }