POJ 2909
1 #include<iostream> 2 #include<stdio.h> 3 #define M 35000 4 #include<math.h> 5 #define N 3800 6 using namespace std; 7 8 int prime [N]; 9 void give_list(); 10 int main() 11 { 12 //freopen("acm.acm","r",stdin); 13 int i; 14 int j; 15 int num; 16 int sum; 17 give_list(); 18 while(cin>>num) 19 { 20 sum = 0; 21 if(num == 0) 22 break; 23 for(i = 1; ;++ i) 24 { 25 for(j = i; ;++ j) 26 { 27 if(prime[i] + prime[j] == num) 28 ++ sum; 29 if(prime[i] + prime[j] > num) 30 break; 31 } 32 if(prime[i] >= num/2) 33 { 34 break; 35 } 36 37 } 38 cout<<sum<<endl; 39 } 40 } 41 42 void give_list() 43 { 44 int i; 45 int j; 46 bool prim1[M]; 47 memset(prim1,true,sizeof(bool)*M); 48 prim1[1] = false; 49 for(i = 2; i < sqrt(long double(M))+1; i ++) 50 { 51 if(prim1[i]) 52 { 53 j = 2*i; 54 while(j < M) 55 { 56 prim1[j] = false; 57 j += i; 58 } 59 } 60 } 61 j = 1; 62 for(i = 2; i < M; i ++) 63 { 64 if(prim1[i]) 65 { 66 prime[j] = i; 67 ++ j; 68 } 69 } 70 }