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

a<0

Posted by mathzqy at 2004-09-06 10:08:45 on Problem 1808
In Reply To:Re:怎么会WA,谢谢 Posted by:PC0400322032 at 2004-09-05 22:52:42
> #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);
a=a%p;a=(a+p)%p;
> 		printf("Scenario #%d:\n%d\n\n",t,done());
> 	}
> }

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