思路
这道题大家都在用快速乘,我用int128就过了。
记得要重载输入输出,然后加个快速幂就好了。
代码
#include<bits/stdc++.h>
#define int __int128
using namespace std;
typedef long long ll;
int fpow(int a,int b,int p){
int res=1;
while(b){
if(b&1) res=res*a%p;
a=a*a%p;
b>>=1;
}
return res%p;
}
inline void read(int &data){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
data=x*f;
}
void write(int x){
if(x>9) write(x/10);
putchar(x%10+'0');
}
signed main(){
int t,a,b,p;
read(t);
while(t--){
read(a);read(b);read(p);
write(fpow(a,b,p));
printf("\n");
}
return 0;
} 
京公网安备 11010502036488号