嗯...
题目链接:http://poj.org/problem?id=1995
快速幂模板...
AC代码:
1 #include2 #include 3 4 using namespace std; 5 6 int main(){ 7 long long N, M, n, a, b, c, sum = 0; 8 scanf("%lld", &N); 9 while(N--){10 scanf("%lld%lld", &M, &n);11 sum = 0;12 for(int i = 1; i <= n; i++){13 c = 1;14 scanf("%lld%lld", &a, &b);15 while(b){16 if(b & 1) c = c * a % M;17 a = a * a % M;18 b /= 2;19 }20 sum += c % M;21 }22 printf("%lld\n", sum % M);23 }24 return 0;25 }