#include <iostream>
using namespace std;

bool ifnotprime[1000000];

void setPrimes(){
    ifnotprime[0] = ifnotprime[1] = true;
    for(int n = 2; n*n < 1000000; n++){
        if( !ifnotprime[n] ){
            int m = n*n;
            while(m < 1000000){
                ifnotprime[m] = true;
                m += n;
            }
        }
    }
}

int main(){
    setPrimes();
    int n, i;
    while(cin >> n, n){
        int ans = 0;
        for(i = 2; i <= n/2; i++){
            if( !ifnotprime[i] && !ifnotprime[n-i] ){
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}