1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <cstdlib> #include <algorithm> #include <cstring> #include <cctype> #define INF 2000000000 using namespace std; typedef long long ll; int (){ int f = 1, x = 0; char c = getchar(); while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar(); } while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar(); return f * x; } int poww(int a, int b, int m){ int res = 1; while(b){ if(b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; } int m, h, dd[45005], ex[45005]; void init(){ m = read(), h = read(); for(int i = 0; i < h; ++i) dd[i] = read(), ex[i] = read(); } void solve(){ int sum = 0; for(int i = 0; i < h; ++i) sum = (sum + poww(dd[i] % m, ex[i], m)) % m; printf("%dn", sum); } int main(){ int T = read(); while(T--) { init(); solve(); } return 0; }
|
近期评论