一. 题目
二. 思路
三. 代码
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e5+10;
using LL=long long;
int n;
class KSM
{
public:
KSM()
{
initIO();
}
void initIO()
{
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
}
LL qmi(LL a, int b, int p)
{
LL ans=1;
while(b)
{
if(b&1) ans=ans*a%p;
a=a*a%p, b>>=1;//a每次随着b右移,进制增加
}
return ans;
}
}ksm;
int main()
{
cin>>n;
while(n--)
{
LL a;
int b, p;
cin>>a>>b>>p;
cout<<ksm.qmi(a, b, p)<<endl;
}
}