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 LZSY1 at 2018-08-25 10:29:36 on Problem 2262 and last updated at 2018-08-25 10:31:23
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int v[1005],t,n,x1,x2;
bool d[1000005];

void prime()
{
	memset(d,1,sizeof(d));
	int k,i,j;bool p;
	v[++t]=2;
	for(i=3;i<=1000;i+=2)
	{
		k=sqrt(i);p=1;
		for(j=3;j<=k;j+=2)
		{
			if(i%j==0)
			{
				p=false;
				break;
			}
		}
		if(p)v[++t]=i;
	}
	for(i=3;i<=1000000;i+=2)
	{
		for(j=1;j<=t;j++)
		{
			if(v[j]>=i)break;
			if(i%v[j]==0)
			{
				d[i]=false;
				break;
			}
		}
	}
}

int main()
{
	prime();
	while(scanf("%d",&n)&&n)
	{
		x1=3;
		while(1)
		{
			x2=n-x1;
			if(d[x1]&&d[x2])
			{
				printf("%d = %d + %d\n",n,x1,x2);
				break;
			}
			x1+=2;
		}
	}
	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