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:请问这题用什么数学解法?

Posted by HG at 2009-05-15 14:10:54 on Problem 2909
In Reply To:请问这题用什么数学解法? Posted by:hdm29682 at 2006-09-13 19:13:03
线性筛素数表先,就这样吧
#include<iostream>
#include<cmath>
using namespace std;
const long N = 32769;
int isPrime[N] = {0};
long prime[N],npPrime = 0;;
int main()
{
	//线性筛素数表
	for(long i = 2 ; i < N ; i++)
	{
		if( !isPrime[i] )
			prime[npPrime++] = i;
		for(long j = 0 ; j < npPrime && prime[j] * i < N ; j++)
		{
			isPrime[prime[j] * i] ++;
			if(!(i % prime[j]))
				break;
		}
	}
	//开始
	long input;
	while(cin>>input,input)
	{
		int count = 0;
		for(int i = 0 ; (input / 2) >= prime[i] ; i++)
			if(!isPrime[input - prime[i]])
				count ++;
		cout<<count<<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