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:110MS,打表。

Posted by jianghuiyou at 2015-08-31 10:07:52 on Problem 2262
In Reply To:110MS,打表。 Posted by:fym0512 at 2012-07-04 21:01:20
> 1140K	110MS
> 如果i是素数,那么判断n-i是否是素数,是的话输出。
> 为神马一开始老wrong answer.不知道原因的情况下再次提交就对了。。神马啊。
> 
> #include <iostream>
> using namespace std;
> #define MAX 1000000
> bool prime[MAX+1];//ini false
> void judgePrime()
> {//==0是素数
> 	for(int i=2;i*i<=MAX;i++)
> 		if(prime[i]==0)
> 			for(int j=i+i;j<=MAX;j += i)
> 				prime[j]=1;
> }
> int main()
> {
> 	judgePrime();
> 	while(1)
> 	{
> 		int n;
> 		scanf("%d",&n);
> 		if(n==0)
> 			break;
> 		for(int i=3;i<=n/2;i += 2)
> 		{
> 			if(prime[i]==0 && prime[n-i]==0)
> 			{
> 				printf("%d = %d + %d\n",n,i,n-i);
> 				break;
> 			}
> 		}
> 	}
> 	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