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:不对,我是筛到10^5的

Posted by 200630551488 at 2010-05-27 15:19:05 on Problem 2262
In Reply To:不对,我是筛到10^5的 Posted by:yuest at 2009-08-20 10:20:30
1000100 AC
1000000 WA
我也如此,各位帮忙看看代码问题再哪,谢谢

#include <iostream>
#include <cmath>
using namespace std;

int* prime = new int[78600];
bool* record = new bool[1000100];
bool isPrime(int n)
{
	if(n < 2)return false;
	if(n == 2) return true;
	else if(n %2 == 0) return false;
	int k = (int)sqrt((double)n);
	int i,j;
	for(i = 3; i<= k; i+=2)
	{
		if(n%i == 0)return false;
	}
	return true;
}
int main()
{
	int i,j=0;
	for(i=0;i<1000100;++i)record[i] = true;
	for(i=0;i<=1000100;++i)
	{
		if(isPrime(i))
		{
			record[i] = false;
			prime[j] = i;
			j++;
		}
	}



	int N;
	while(1)
	{
		bool haveresult = false;
		cin >> N;
		if(N == 0)
			break;
		for(i = 1; i<= 78600; ++i)
		{
			if(!record[prime[i]] && !record[N-prime[i]])
			{
				printf("%d = %d + %d\n",N,prime[i],N-prime[i]);
				haveresult = true;
				break;
			}
		}
		if(!haveresult)
			cout<< "Goldbach's conjecture is wrong."<<endl;

	}
	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