【快速幂】AcWing875.快速幂——模板题
AcWing875.快速幂

题解
#include <iostream>
using namespace std;
typedef long long LL;
int main()
{
int n, a, b, p;
cin >> n;
while(n -- )
{
int res = 1;
cin >> a >> b >> p;
while(b)
{
if(b & 1) res = res * (LL)a % p;
b >>= 1;
a = a * (LL)a % p;
}
cout << res << endl;
}
return 0;
}

浙公网安备 33010602011771号