标签:
HDU - 5666| Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
Description






















Input






































Output




Sample Input
1 2 107
Sample Output
0
Source
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define ll __int64
using namespace std;
ll p_mod(ll q1,ll q2,ll p)
{
ll sum=0;
while(q2)
{
if(q2&1)
{
sum+=q1;
sum%=p;
}
q1<<=1;
q1%=p;
q2>>=1;
}
return sum;
}
int main()
{
int t,n,m;
ll p,q;
ll q1,q2,pp;
int i,j,k;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld",&q,&p);
q1=q-1;q2=q-2;
if(q1&1)
q2>>=1;
else
q1>>=1;
printf("%lld\n",p_mod(q1,q2,p));
}
return 0;
}标签:
原文地址:http://blog.csdn.net/yanghui07216/article/details/51200328