Raising Modulo Numbers 快速幂取模基础
#include <stdio.h>#include <cmath>long long quick_mod(long long a,long long b,int m){ long long ans=1; while(b) { if(b&1) { ans=(ans*a)%m; b--; } b/=2; a=a*a%m; } return ans;}int main(){ int t,n,m; scanf("%d",&t); long long a,b; while(t--) { scanf("%d",&m); scanf("%d",&n); int sum=0; while(n--) { scanf("%lld%lld",&a,&b); sum+=quick_mod(a,b,m); } printf("%d\n",sum%m); } return 0;}