Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:水中之水

Posted by ewzyq at 2013-09-27 11:11:55 on Problem 1995
In Reply To:水中之水 Posted by:ewzyq at 2013-09-27 11:10:44
#include<stdio.h>
#define MAX 45000+20
typedef long long ll;
ll a[MAX];
ll b[MAX];
ll qmod(ll a,ll b,ll c)
{
	ll ans=1;
	a=a%c;
	while(b>0)
	{
		if(b&1)
		ans=ans*a%c;
		a=a*a%c;
		b>>=1;
	}
	return ans;
}
int main()
{
	int t;
	ll c;
	int n;
	while(~scanf("%d",&t))
	{
		for(int k=0;k<t;k++)
		{
			scanf("%I64d %d",&c,&n);
			ll ans=0;
			ll res;
			for(int i=0;i<n;i++)
			{
				scanf("%I64d %I64d",&a[i],&b[i]);
				res=qmod(a[i],b[i],c);
				ans=(ans+res)%c;
			}
			ans=ans%c;
			printf("%I64d\n",ans);
		}
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator