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 dynamic_study at 2009-07-17 17:53:37 on Problem 2909
#include<iostream>
#include<algorithm>
using namespace std;
#define N 10000
bool a[10000];
long p[10000] ;
void creat(void)
{
	    long i,num;
        memset(a, true, sizeof(a));
        num = 0;
        for(i = 2; i < N; ++i)
        {
            if(a[i])
               p[num++] = i;
            for(int j = 0; (j<num && i*p[j]<N); ++j)
            {
                a[i*p[j]] = false;
                if(i%p[j]==0) break;
            }
        }
}
int main()
{
	long  k,ans;
	long n,s,b;
	creat();
	while(cin>>n&&n!=0)
	{
	    k=0;
		ans=0;
		while(1)
		{
			s=p[k];
			b=n-s;
			if(s>b)
				break;
			if(a[b])
			{
				ans++;
				k++;
			}
			else
				k++;
		}
		cout<<ans<<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