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:使用欧拉准则计算勒让德符号,直接计算a^((p-1)/2) 是否为1既可

Posted by 782423381 at 2009-08-11 09:23:03 on Problem 1808
In Reply To:使用欧拉准则计算勒让德符号,直接计算a^((p-1)/2) 是否为1既可 Posted by:majia5 at 2009-07-26 13:10:43
#include <iostream>
using namespace std;
int a,p;
long long  mod2(int k)
{
	int i;
	long long m;
	m = a%p;
	for(i=0;i<k;i++)
		m = (m*m)%p;
	return m;
}
int done()
{
	int k,q=p/2;
	long long 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;
}
int main()
{
	int t,tt;
	scanf("%d",&tt);
	for(t=1;t<=tt;t++)
	{
		scanf("%d%d",&a,&p);
		if(a<0&&(p-3)%4==0)
		{
			a=-a;
		   printf("Scenario #%d:\n%d\n\n",t,(-1)*done());
		}
		else 
		{
			if(a<0&&(p-1)%4==0) a=-a;
			printf("Scenario #%d:\n%d\n\n",t,done());
		}

	}
	return 0;
}
...可不可以讲一下他的计算思路。。看不懂啊

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