| ||||||||||
| 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 | |||||||||
Re:怎么会WA,谢谢In Reply To:直接使用(a/p)=a^(p-1)/2即可 Posted by:mathzqy at 2004-08-27 10:17:56 #include <stdio.h>
int a,p;
__int64 mod2(int k)
{
int i;
__int64 m;
m = a%p;
for(i=0;i<k;i++)
m = (m*m)%p;
return m;
}
int done()
{
int k,q=p/2;
__int64 m(1);
for(k=0;k<32;k++)
if(((1<<k)&q)>0)
m = m*mod2(k)%p;
if(m==1)
return 1;
else
return -1;
}
void main()
{
int t,tt;
scanf("%d",&tt);
for(t=1;t<=tt;t++)
{
scanf("%d%d",&a,&p);
printf("Scenario #%d:\n%d\n\n",t,done());
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator