#include <stdio.h> #include <stdlib.h> #include <math.h> #define MAX_N 3512 int *plist; int np=4;
int isPrime(int n) { int i; int d=(int)sqrt(n)+1; for(i=0;plist[i]<d;i++) { if(i>=np)printf("error"); if(n%plist[i]==0)return 0; } return 1; } int isPrimeInList(int n) { int lo = 0, hi = np - 1; int t; while(lo < hi) { t = lo + hi >> 1; if (plist[t] == n) return true; if (plist[t] > n) hi = t - 1; else lo = t + 1; } return lo == hi && plist[lo] == n; }
int main() { int i,m,n; np=4; plist=new int[MAX_N]; plist[0] = 2; plist[1] = 3; plist[2] = 5; plist[3] = 7; for(i=9;i<32768;i+=2) { if(isPrime(i)) plist[np++] = i; }
while(scanf("%d",&n)==1 && n>0) { m = 0; if (n % 2) { if (isPrimeInList(n-2)) m = 1; } else { for (i=0;i<np;i++) { if (plist[i] > (n>>1)) break; if (isPrimeInList(n - plist[i])) m++; } } printf("%d\n",m); } delete [] plist; return 0; }