#include<stdio.h>
#define MAX 40000
int N,P[MAX],F[MAX]={0},i,j,p=0,r;

int main()
{
	for(i=2;i<MAX;i++)if(!F[i]){P[p++]=i;for(j=i*2;j<MAX;j+=i)F[j]=1;}
	for(;scanf("%d",&N),N;)
	{
		r=0;
		for(i=0;P[i]&&P[i]<=N/2;i++)
			if(!F[N-P[i]])
				r++;
		printf("%d\n",r);
	}
	return 0;
}