#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 ;
}
相关文章
- HDU 3117 Fibonacci Numbers( 矩阵快速幂 + 数学推导 )
- POJ3641-Pseudoprime numbers(快速幂取模)
- UVa 11582 (快速幂取模) Colossal Fibonacci Numbers!
- Raising Modulo Numbers(POJ 1995 快速幂)
- 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 (快速幂)