#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

vector<bool> eratos(int n)
{
	vector<bool> isprime(n+1, true);
	isprime[0] = isprime[1] = false;
	for(int i=2; i*i<=n; ++i){
		if(isprime[i]){
			for(int j=i*2; j<=n; j+=i)
				isprime[j] = false;
		}
	}
	return isprime;
}

int main()
{
	vector<bool> isprime = eratos(1000000);
	
	int n;
	while(scanf("%d", &n), n){
		int cnt = 0;
		rep(i, n/2+1)
			cnt += isprime[i] && isprime[n-i];
		printf("%d\n", cnt);
	}
	return 0;
}