#include <iostream>
#include <vector>
#include <algorithm>
#define sup 1000000
using namespace std;

bool isinthevector(std::vector<int> v,int n)
{
	std::vector<int>::iterator i=find(v.begin(), v.end(),n);
	return i!=v.end();
}

int main(int argc, char const *argv[])
{
	std::vector<int> prm;
	prm.push_back(2);prm.push_back(3);
	bool isprm;
	for(int n=5;n<=sup;n+=2,isprm=true)
	{
		for (int i=0;prm[i]*prm[i]<=n;++i)
		{
			if(n%prm[i]==0)
			{
				isprm=false;
				break;
			}
		}
		if (isprm==true)
		{
			prm.push_back(n);
		}
	}

	int n;
	while(cin>>n,n)
	{
		int cnt=0;
		for (int i=0;2*prm[i]<=n;++i)
		{
			if (isinthevector(prm,n-prm[i]))
			{
				++cnt;
			}
		}
		cout<<cnt<<"\n";
	}
	return 0;
}