Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:请问这题用什么数学解法?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator