| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
只能是二分取摸!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator