#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
bool us[1000010]={false};
int p[1000010] = {0};
int main(){
	/*Eratosthenes*/
	p[0] = 2;
	for(int i = 0; i <= 1000010; i+=2){
		us[i] = true;
	}
	
	int cnt = 1;
	for(int i = 3; i <= 1000010; i+=2){
		int q = 0;
		if(us[i] == true)continue;
		else if(us[i] == false){
			p[cnt] = i;
			cnt++;
			us[i] = true;
			q = i;
			for(int j = q+q; j <= 1000010; j += q){
				us[j] = true;
			}
		}
	}
	
	int n;
	while(scanf("%d",&n),n){
		int x = 0;
		memset(us,false,sizeof(us));
		for(int i = 0; i < n/2; i++){
			if(us[i] == true)continue;
			if(us[i] >= n)break;
			for(int j = i; j < n/2; j++){
				if(p[i] + p[j] > n)break;
				if(p[j] == true){
					if(p[i] +p[j] < n)continue;
					else break;
				}
				if(binary_search(p,p + (n/2),(n-p[i]))){
					x++;
					us[i] = true;
					us[j] = true;
					break;
				}
			}
		}
		printf("%d\n",x);
	}
	return 0;
}