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

const int MAX = 50;
bool isPrime[MAX];

void next(int& i) {
    while (++i < MAX && isPrime[i] == false);
}

void prev(int& i) {
    while (--i > 0 && isPrime[i] == false);
}

int main() {
    fill_n(isPrime, MAX, true);
    for (int i = 4; i < MAX; i += 2) {
        isPrime[i] = false;
    }
    for (int i = 3; i * i <= MAX; i += 2) {
        if (isPrime[i]) {
            for (int j = 2 * i; j < MAX; j += i) {
                isPrime[j] = false;
            }
        }
    }
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int count = 0, a = 2, b = n;
        prev(b);
        while (a <= b) {
            if (a + b < n) {
                next(a);
            } else if (a + b > n) {
                prev(b);
            } else {
                count++;
                next(a);
                prev(b);
            }
        }
        cout << count << endl;
    }
}