#include<iostream> #include<algorithm> using namespace std; #define ll long long int qmi(ll a, ll b, ll mod) { //求 a^b%p,时间复杂度 O(logn) ll flag = 1; while (b) { if (b & 1)flag = (flag*a)%mod; a = (a*a) % mod; b = b >> 1; } return flag%mod; } int qji(ll a, ll b, ll mod) { //求 a*b%p,时间复杂度 O(logn) ll flag = 0; while (b) { if (b & 1)flag = (flag + a) % mod; a = (a << 1) % mod; b = b >> 1; } return flag%mod; } int main() { ll a, b, c; cin >> a >> b >> c; cout << a << "^" << b << " mod " << c << "=" << qmi(a, b, c) << " "; cout << a << "*" << b << " mod " << c << "=" << qji(a, b, c) << " "; return 0; }