new file: 2.cpp
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// 5579
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
int t;
|
||||
int pow(int a, int b, int p)
|
||||
{
|
||||
a %= p;
|
||||
int res = 1;
|
||||
while (b > 0)
|
||||
{
|
||||
if (b % 2)
|
||||
res *= a, res %= p;
|
||||
a = a * a % p,b>>=1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d", &t);
|
||||
while (t--)
|
||||
{
|
||||
int m, h;
|
||||
scanf("%d%d", &m, &h);
|
||||
int ans = 0;
|
||||
for (int i = 1; i <= h; ++i)
|
||||
{
|
||||
int a, b;
|
||||
scanf("%d%d", &a, &b);
|
||||
ans += pow(a, b, m);
|
||||
ans %= m;
|
||||
}
|
||||
printf("%d\n", ans);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user