- #include
- #define int long long
- using namespace std;
- int power(int a,int b,int p)
- {
- int ans = 1;
- while(b > 0)
- {
- if(b & 1) ans = ans * a % p;
- b >>= 1;
- a = a * a % p;
- }
- return ans;
- }
- signed main()
- {
- int a,b,p;
- cin >> a >> b >> p;
- cout << a << "^" << b << " mod " << p << "=" << power(a,b,p) << endl;
- return 0;
- }