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

#define MAX_N 1000001

bool table[MAX_N];

void init() {
    memset(table, 1, sizeof(table));
    table[0] = table[1] = false;
    for (int i = 2; i < MAX_N; i++) {
        if (table[i]) {
            for (int j = i + i; j < MAX_N; j += i) {
                table[j] = false;
            }
        }
    }
}

int main() {
    init();
    int n;
    while (cin >> n) {
        if (n == 0) break;
        int count = 0;
        for (int i = 2; i <= n/2; i++) {
            if (table[i] && table[n - i]) {
//                cout << i << ' ' << n - i << endl;
                count++;
            }
        }
        cout << count << endl;
    }
    return 0;
}