码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 1995

时间:2014-09-17 21:40:52      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:blog   io   os   for   div   sp   log   c   amp   

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define LL __int64
using namespace std;

LL M;

LL quick(LL a,LL b){
	a%=M;
	LL ans=1;
	while(b){
		if(b&1)
		ans=(ans*a)%M;
		b>>=1;
		a=(a*a)%M;
	}
	return ans;
}

int main(){
	int T,n;
	LL a,b;
	scanf("%d",&T);
	while(T--){
		LL ans=0;
		scanf("%I64d",&M);
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%I64d%I64d",&a,&b);
			ans=(ans+quick(a,b))%M;
		}
		printf("%I64d\n",ans);
	}
	return 0;
}

  

POJ 1995

标签:blog   io   os   for   div   sp   log   c   amp   

原文地址:http://www.cnblogs.com/jie-dcai/p/3978026.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!