题目链接
题意
给你几组数,求下面这个式子:
代码
#include <iostream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll getMod(ll base,ll top,ll mod)
{
ll r=1;
while(top)
{
if(top&1)
r = (r*base)%mod;
top>>=1;
base = (base*base)%mod;
}
return r;
}
int main()
{
int z;
cin>>z;
while(z--)
{
ll m,h;
int ans=0;
cin>>m>>h;
ll base,top;
while(h--)
{
cin>>base>>top;
ans = (ans+getMod(base,top,m))%m;
}
cout<<ans<<endl;
}
return 0;
}