#include <cstdio>
typedef long long ll;
int quick_pow(ll a,ll b,ll mod){
ll ans=;
for(;b;a=(a*a)%mod,b>>=)if(b&)ans=(ans*a)%mod;
return ans;
}
int main(){
int z,m,h,a,b,ans;
for(scanf("%d",&z);z--;){
scanf("%d%d",&m,&h),ans=;
while(h--)scanf("%d%d",&a,&b),ans=(ans+quick_pow(a,b,m))%m;
printf("%d\n",ans);
}
return ;
}
相关文章
- poj 3641 Pseudoprime numbers(快速幂)
- hdu 2817 A sequence of numbers(快速幂)
- POJ 1995 Raising Modulo Numbers (快速幂)
- HDU 2817 A sequence of numbers 整数快速幂
- 【POJ - 3641】Pseudoprime numbers (快速幂)
- Uva 10006 Carmichael Numbers (快速幂)
- POJ1995 Raising Modulo Numbers(快速幂)
- 【UVA - 10006 】Carmichael Numbers (快速幂+素数筛法)
- POJ-3641 Pseudoprime numbers---快速幂
- HDU 3641 Pseudoprime numbers(快速幂)