mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-09-19 01:25:25 +00:00
875. 快速幂
https://www.acwing.com/problem/content/submission/code_detail/7249810/
This commit is contained in:
parent
4bc93bb684
commit
5c4e71b2c0
25
AcWing/875/875.cpp
Normal file
25
AcWing/875/875.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
long long binpow(long long a, long long b, long long m) {
|
||||||
|
a %= m;
|
||||||
|
long long res = 1;
|
||||||
|
while (b > 0) {
|
||||||
|
if (b & 1) res = res * a % m;
|
||||||
|
a = a * a % m;
|
||||||
|
b >>= 1;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int n;
|
||||||
|
cin >> n;
|
||||||
|
while (n--) {
|
||||||
|
long long a, b, p;
|
||||||
|
cin >> a >> b >> p;
|
||||||
|
cout << binpow(a, b, p) << endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user