#include <stdio.h>#include<stdlib.h>#include<math.h>intIspri (intAintb) { inti; for(i=2; I <= sqrt (a); i++) { if(a%i = =0) return 0; } for(i=2; I <= sqrt (b); i++) { if(b%i = =0) return 0; } return 1;}intMain () {intn,flag,i,cout; while(SCANF ("%d", &n)! = EOF &&N) {cout=0; for(i=2; i< n/2+1; i++) {flag=ispri (i,n-i); if(Flag = =1) cout++; } printf ("%d\n", cout); } return 0;}
View Code
We use the Eratosthenes sieve method to play the table
Algorithm Description: Less than 2 is not a prime, with an array of a[10000], the element subscript indicates the number, the value of the element is the prime, C + + practice is, bool a[10000], will a[0] and A[1] assigned 0, starting from 2, 2*2,2*3 ...
2*6. These subscript corresponding element values are changed to 0, in this environment again looking for the next prime, once again, 3*2,3*3,3*4 ... product overall less than 10000
inta[10000]; a[0]=0; a[1]=0; for(i=2;i<10000; i++) A[i]=1; for(i=2;i<10000; i++) { if(A[i] = =1) { for(j=2;j<10000; j + +) {A[i*J] = =0; } } } for(intj=2; j<=n;++j) { if(isprimes[j]==true) for(intm=2; j*m<=n;++m) Isprimes[j*m] =false;
View Code
See:
http://blog.csdn.net/kingwolfofsky/article/details/7199758
poj2909 | | poj2262