#include<stdio.h>
#include<bitset>
int main()
{
	const int N=1000001;
	int i,j,n,c;
	std::bitset<N>p;
	p.set();
	for(i=2;i*2<N;++i)if(p[i])for(j=2*i;j<N;j+=i)p[j]=0;
	while(scanf("%d",&n),n)
	{
		for(c=0,i=j=n/2;i>1;--i,++j)if(p[i]&&p[j])c++;
		printf("%d\n",c);
	}
	return 0;
}