0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-30 16:56:27 +00:00
OI-codes/Luogu/P1226/P1226.cpp
2022-01-17 09:08:49 +08:00

24 lines
437 B
C++

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
long long binpow(long long a, long long b, long long m) {
long long res = 1;
a %= m;
while (b) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
int main() {
long long a, b, p;
cin >> a >> b >> p;
cout << a << '^' << b << " mod " << p << '=' << binpow(a, b, p) << endl;
return 0;
}