快速幂模板题
#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; }