题解 | #【模板】快速幂Ⅰ ‖ 整数#
【模板】快速幂Ⅰ ‖ 整数
https://www.nowcoder.com/practice/3d624107a6904da1bd0e8c9c85e17167
快速幂模板题
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
int __t = 1, n, a, b, p;
int kpow(int a, int b, int p) {
int ans = 1;
while (b) {
if (b & 1)
ans = ans * a % p;
a = a * a % p;
b >>= 1;
}
return ans % p;
}
void solve() {
cin >> a >> b >> p;
cout << kpow(a, b, p) << "\n";
return;
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false);
cin.tie(0);
#endif
cin >> __t;
while (__t--)
solve();
return 0;
}
查看10道真题和解析