#include<stdio.h>
long long power(long long x,long long y,long long p){
long long sum=1;
while(y){
if(y&1){
sum=sum*x%p;
}
y/=2;
x=x*x%p;
}
return sum;
}
int z;//the number of assignments
long long m;
int h;//number of players
long long a[45001],b[45001];
long long s;//the sum
main(){
scanf("%d",&z);
int i;
for(i=0;i<z;i++){
scanf("%lld",&m);
scanf("%d",&h);
int j;
for(j=0;j<h;j++){
scanf("%lld %lld",&a[j],&b[j]);
}
s=0;
i=0;
while(i<h){
s=s+power(a[i],b[i],m);
i++;
}
printf("%lld",s%m);
}
}
自测显示,当z=1时答案正确,但z>1时,for循环体中的代码只能执行一次