#include <bits/stdc++.h>
using namespace std;

vector<bool> IsPrime;
vector<int> primes;

void sieve(int max) {
    IsPrime.resize(max + 1, true);
    IsPrime[0] = IsPrime[1] = false;
    for (int i = 2; i * i <= max; ++i){
        if (IsPrime[i]){
            for (int j = i * i; j <= max; j += i) IsPrime[j] = false;
        }
    }
    for(int i = 0; i <= max; ++i) if(IsPrime[i])primes.push_back(i);
}

int main() {
    sieve(int(1e6));
    int n;
    while(cin >> n, n){
        int ans = 0;
        for(int i=0;primes[i]*2<=n;i++){
            if(IsPrime[n-primes[i]]) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}
