#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;

const int MX = 1000001;
bool sieve[MX];

int main() {
    memset(sieve, 0, sizeof sieve);
    sieve[0] = sieve[1] = true;
    for (int i=2; i*i<MX; ++i) {
        if (sieve[i]) continue;
        for (int j=i*i; j<MX; j+=i) {
            sieve[j] = true;
        }
    }
    int n;
    while (cin >> n, n) {
        int cnt = 0;
        for (int i=0; 2*i<=n; ++i) {
            if ( ! sieve[i] && ! sieve[n-i]) {
                ++ cnt;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}