快速幂模板。
#include<bits/stdc++.h>
#define int long long
#define double long double
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 3e5 + 10;
const int M = 1e3 + 10;
int mod = 1e9 + 7;
// int a[N];
int ksm(int a, int b, int c) {
a %= c;
int res = 1;
if (b == 0) return 1 % c;
while (b) {
if (b & 1)res = (res * a) % c;
a = (a * a) % c;
b >>= 1;
}
return res;
}
void solve() {
int a, b, c;
cin >> a >> b >> c;
int ans = ksm(a, b, c);
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int _;
_ = 1;
cin >> _;
while (_--) {
solve();
}
}

京公网安备 11010502036488号