#include <iostream>

using namespace std;

const int NUM = 1000001;
bool prime[NUM];

void init()
{
    for (int i = 0; i < NUM; i++)
        prime[i] = true;
    prime[0] = prime[1] = false;

    for (int i = 2; i * i < NUM; i++) 
        for (int j = 2 * i; j < NUM; j += i) 
            if (prime[j])
                prime[j] = false;
}

int main()
{
    int n;

    init();
    while (cin >> n, n) {
        int cnt = 0;

        for (int i = 2; i <= n - i; i++) 
            if (prime[i] && prime[n - i]) 
                cnt++;

        cout << cnt << endl;
    }

    return 0;
}