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

int main() {
    set<int> primes;
    primes.insert(2);
    for (int i = 3; i < 50000; i += 2) {
        bool add = true;
        for (set<int>::iterator it = primes.begin(); it != primes.end(); it++) {
            if ((*it) * (*it) > i) {
                break;
            }
            if (i % (*it) == 0) {
                add = false;
                break;
            }
        }
        if (add) {
            primes.insert(i);
        }
    }
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int count = 0;
        set<int>::iterator itSmall = primes.begin(), itBig = primes.lower_bound(n);
        while ((*itSmall) <= (*itBig)) {
            if (*itSmall + *itBig > n) {
                itBig--;
            } else if (*itSmall + *itBig < n) {
                itSmall++;
            } else {
                count++;
                itSmall++;
                itBig--;
            }
        }
        cout << count << endl;
    }
}