#include<iostream>
int prime[100001] = {0};

void func(int n);

int main(){
	int n;
	while (std::cin >> n, n){
		func(n);
		/*for (int i = 0; i < n; ++i){
			if(prime[i]==1)std::cout << i << std::endl;
		}*/
		int ans = 0;
		for (int i = 2; i <= n / 2; ++i){
			if (prime[i] == 1 && prime[n - i] == 1){
				ans++;
				//std::cout << i << " " << n - i << std::endl;
				prime[i] = 0;
				prime[n - i] = 0;
			}
		}
		std::cout << ans << std::endl;
		
	}
}

void func(int n){
	for (int i = 2; i <= n; ++i){
		if (!prime[i]){
			prime[i] = 1;
			for (int j = 2; i*j <= n; ++j){
				prime[i*j] = 2;
			}
		}
	}
}