0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 22:08:47 +00:00

P1226 【模板】快速幂||取余运算

R66944240
This commit is contained in:
Baoshuo Ren 2022-01-17 09:08:49 +08:00
parent e31a7ee8a2
commit 3bc27c14ff
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

23
Luogu/P1226/P1226.cpp Normal file
View File

@ -0,0 +1,23 @@
#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;
}