mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
P1226 【模板】快速幂||取余运算
R66944240
This commit is contained in:
parent
e31a7ee8a2
commit
3bc27c14ff
23
Luogu/P1226/P1226.cpp
Normal file
23
Luogu/P1226/P1226.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user