#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e13
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007


/*nまでの素数を列挙して配列に保持*/
vector<int> Eratosthenes(int n,vector<int>& arr){

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

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


int main(){


    int n;
    int tmp = 1000000;
    vector<int> arr(tmp);


    arr = Eratosthenes(tmp,arr);/*50000までの素数を列挙*/
    
    while(cin >> n,n){
        int count = 0;
        for(int i = 2;i <= n/2;i++){

            if(i <= n-i && arr[i] && arr[n-i]){
                count++;
            }
        }
        cout << count << endl;
    }
    
    
    return 0;
}
