//172k, 79ms
#include <iostream>
using namespace std;
//x的n次方对mod取模
int mod_pow(int x, int n, int mod) {
int res = 1;
while(n > 0) {
if(n & 1) res = res * x % mod;
x = (x % mod) * (x % mod) % mod;
n >>= 1;
}
return res;
}
const int MAX_H = 45005;
int z, m, h;
int arr[MAX_H];
int main() {
freopen("in.txt", "r", stdin);
scanf("%d", &z);
while(z--) {
scanf("%d%d", &m, &h);
int res = 0;
int a, b;
while(h--) {
scanf("%d%d", &a, &b);
res = res + mod_pow(a, b, m);
}
printf("%d\n", res % m);
}
fclose(stdin);
return 0;
}
poj1995
最新推荐文章于 2020-03-28 20:40:35 发布