#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

ll arr[1000010];

void Eratosthenes(ll n) {
	for (int i = 0; i <= n; i++)
		arr[i] = 1;

	for (int i = 2; i <= sqrt(n); i++) {
		if (arr[i]) {
			for (int j = 0; i*(j + 2) <= n; j++)
				arr[i*(j + 2)] = 0;
		}
	}
}

int main()
{
	ll n;
	while (cin >> n, n)
	{
		ll cnt = 0;
		Eratosthenes(n);
		for (int i = 2; i <= n / 2 + n % 2; i++) {
			if (arr[i]) {
				if (arr[n - i])cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}