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

const int MAX = 1000000;
int primes[80000];
int pNum;

void calcPrimes() {
    primes[0] = 2;
    pNum = 1;
    for (int i = 3; i <= MAX; i += 2) {
        bool add = true;
        for (int j = 0; j < pNum; j++) {
            if (primes[j] * primes[j] > i) {
                break;
            }
            if (i % primes[j] == 0) {
                add = false;
                break;
            }
        }
        if (add) {
            primes[pNum++] = i;
        }
    }
}

int main() {
    calcPrimes();
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int pi = 0, qi = pNum - 1, ans = 0;
        while (pi <= qi) {
            int sum = primes[pi] + primes[qi];
            if (sum <= n) {
                if (sum == n) {
                    ans++;
                }
                pi++;
            } else {
                qi--;
            }
        }
        cout << ans << endl;
    }
}