嗯...
题目链接:http://poj.org/problem?id=1995
快速幂模板...
AC代码:
#include<cstdio>
#include<iostream> using namespace std; int main(){
long long N, M, n, a, b, c, sum = ;
scanf("%lld", &N);
while(N--){
scanf("%lld%lld", &M, &n);
sum = ;
for(int i = ; i <= n; i++){
c = ;
scanf("%lld%lld", &a, &b);
while(b){
if(b & ) c = c * a % M;
a = a * a % M;
b /= ;
}
sum += c % M;
}
printf("%lld\n", sum % M);
}
return ;
}
AC代码