快速幂。
如果幂是偶数,除2 底乘2
否则 结果乘底
#include<bits/stdc++.h>
#define maxn 11111
#define LL long long
using namespace std;
int main(){
int T;
LL a,b,c;
scanf("%d",&T);
while(T--){
scanf("%lld %lld %lld",&a,&b,&c);
LL ans=1;
while(b){
if(b&1){
ans=((ans%c)*(a%c))%c;
b-=1;
}
b/=2;
a=((a%c)*(a%c));
}
//ans=((ans%c)*(a%c))%c;
printf("%lld\n",ans);
}
return 0;
}