#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll b,p,k; cin >> b >> p >> k; ll a = 1; //b^p % k for(int i=1;i<=p;++i) a = a*b%k; cout << b << '^' << p << " mod " << k << "=" << a << endl; }