#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 1000001

bool isPrime[MAX];

void eratos() {
    fill(isPrime, isPrime + MAX, true);
    for (int i = 2; i < MAX; i++) {
        if (!isPrime[i]) continue;
        for (int j = i + i; j < MAX; j += i) {
            isPrime[j] = false;
        }
    }
}

int main() {
    eratos();
    int n;
    while (true) {
        cin >> n;
        if (n == 0) return 0;
        int count = 0;
        for (int i = 2; i <= n / 2; i++) {
            if (!isPrime[i]) continue;
            if (isPrime[n - i]) count++;
        }
        cout << count << endl;
    }
}