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

只能是二分取摸!

Posted by chenxuan123456789 at 2012-07-29 10:25:29 on Problem 1995
#include <stdio.h>
__int64 rmq(__int64 a,__int64 b,__int64 m)
{
   __int64 sum=1;
   while(b)
   {
   	if(b&1)
   	sum=(a*sum)%m;
   	b/=2;
   	a=(a%m)*(a%m)%m;
   }
   return sum;
}
int main()
{
int cases,n;
__int64 m,a,b,total;
scanf("%d",&cases);
while(cases--)
{
	scanf("%I64d",&m);
	scanf("%d",&n);
	total=0;
	while(n--)
	{
		scanf("%I64d%I64d",&a,&b);
		total+=rmq(a,b,m);
	}
	printf("%I64d\n",total%m);
}
return 1;
}
		
		 
		
		
	

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