题解 | #快速幂#
快速幂
https://www.nowcoder.com/practice/defdedf4fe984c6c91eefa6b00d5f4f0
//快速幂模版
#include <iostream>
using namespace std;
int main() {
int q;
cin>>q;
long long a, b, p;
long long base;
for(int i=0;i<q;++i){
cin>>a>>b>>p;
base = 1;
while(b){
if(b%2!=0){
base = base * a;
}
base = base % p;
a *= a;
a = a%p;
b /= 2;
}
cout<<base<<endl;
}
}
// 64 位输出请用 printf("%lld")