#include<iostream>
#include<vector>
#define MAX 500000
using namespace std;
int main(){
	vector<int> a(MAX);
	vector<int> box(MAX);
	int n,sum,k=0,l,r,mid;
	for(int i=0;i<MAX;i++)
	a[i]=1;
	a[0]=0;a[1]=0;
	for(int i=0;i*i<MAX;i++)
	if(a[i]){
		for(int j=i*2;j<MAX;j+=i)
		a[j]=0;
	}
	for(int i=0;i<MAX;i++)
	if(a[i])
	box[k++]=i;
	while(cin>>n,n){
		sum=0;
		for(int i=0;box[i]<n;i++){
			if(box[i]*2<n)
			continue;
				l=0;r=i;
				while(r-l>1){
					mid=(r+l)/2;
					if(box[mid]>=n-box[i]){
						r=mid;
					}else {
						l=mid;
					}
				}
			if(box[r]+box[i]==n){
				sum++;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}