poj1995

来源:互联网 发布:python 量化分析 编辑:程序博客网 时间:2024/06/05 03:50
#include<iostream>#include<cstdio>#include<cstdlib>typedef long long LL;using namespace std; LL  pow(LL a,LL p,LL m){ LL d=1,t=a;     while(p>0){      if(p&1==1){         d=(d*t)%m;        }       t=(t*t)%m;        p=p>>1;     }return d;}int main(){int c,m,h,a,p;LL sum;scanf("%d",&c);while(c--){   sum=0;   scanf("%d%d",&m,&h);   for(int i=1;i<=h;i++){        scanf("%d%d",&a,&p);             sum=(sum+pow(a,p,m))%m;            }    printf("%d\n",sum);  }return 0;}
0 0
原创粉丝点击