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

神啊 救救我吧~

Posted by abilitytao at 2008-08-10 01:44:57 on Problem 3641 and last updated at 2008-08-10 01:51:19
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int Prime(int x)
{
	int i;
	if (x==2)
	{
		return 1;
	}

	if (x%2==0)
	{
		return 0;
	}

	for (i=3;i<sqrt((float)x);i+=2)
	{
		if (x%i==0)
		{
			return 0;
		}
	}

	return 1;
}

int main()
{
	int i;
	__int64  temp,p,a,a_1000;        
	while(scanf("%I64d %I64d",&p,&a))
	{
		if (p==0&&a==0)
			break;
		if (Prime(p))
			{
				cout<<"no"<<endl;
				continue;
			}
		a_1000=a;
		temp=1;
		
		
			for(i=1;i<1000;i++)
			{
				a_1000=(a_1000*a)%p;
			}
			
			for(i=1;i<=p/1000;i++)
				temp=(temp*a_1000)%p;
			for(i=1;i<=p%1000;i++)
				temp=(temp*a)%p;
	
		if(temp==a)
			printf("yse\n");

		else
			printf("no\n");
	}
	return 0;
}
这份代码 呈上后 结果是华丽的WA
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int Prime(int x)
{
	int i;
	if (x==2)
	{
		return 1;
	}

	if (x%2==0)
	{
		return 0;
	}

	for (i=3;i<sqrt((float)x);i+=2)
	{
		if (x%i==0)
		{
			return 0;
		}
	}

	return 1;
}

int main()
{
	int i;
	__int64  temp,p,a,a_1000;        
	while(scanf("%I64d %I64d",&p,&a))
	{
		if (p==0&&a==0)
			break;
		if (Prime(p))
			{
				cout<<"no"<<endl;
				continue;
			}
		a_1000=a;
		temp=1;
		
		
			for(i=1;i<1000;i++)
			{
				a_1000=(a_1000*a)%p;
			}
			
			for(i=1;i<=p/1000;i++)
				temp=(temp*a_1000)%p;
			for(i=1;i<=p%1000;i++)
				temp=(temp*a)%p;
	
		if(temp==a)
			cout<<"yes"<<endl;


		else
			cout<<"no"<<endl;

	}
	return 0;
}



而这个程序 上交后 居然神奇的AC了
不同的地方只不过是我将c的输出换成了c++的标准输出 但是,这又有什么区别呢
我实在是弄不明白 还请高手指点下 qq:64076241
 


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