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

一次ac,不过要16ms,求0ms做法

Posted by TSERROF at 2012-09-10 14:54:31 on Problem 2909
#include <cstdio>
#include <cstring>
const int N = 50000;
bool a[N];
int p[N];
int n=50000;
void Prime2() 
{
	memset(a, 0, n*sizeof(a[0]));
	int num = 0, i, j;
	for(i = 2; i < n; ++i) 
	{
		if(!(a[i])) p[num++] = i;
		for(j = 0; (j<num && i*p[j]<n); ++j) 
		{
			a[i*p[j]] = 1;
			if(!(i%p[j])) break;
		}
	}
}
int main()
{
	int number;
	Prime2();
	a[0]=true,a[1]=true;
	while(scanf("%d",&number)!=EOF && number)
	{
		int ans=0;
		for(int i=0;p[i]<number/2+1;++i)if(!a[number-p[i]])++ans;
		printf("%d\n",ans);
	}
	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