#include <iostream>
using namespace std;

int main()
{
	int n;
	bool p[50001] = {false};
	
	p[2] = p[3] = p[5] = p[7] = true;
	
	for (int i = 2; i < 50001; i++){
		if (i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0){
			p[i] = true;
		}
	}
	while (cin >> n, n){
		int c = 0;
		for (int i = 2; i <= n / 2; i++){
			if (p[i] && p[n - i]){
				c++;
			}
		}
		cout << c << endl;
	}
	return (0);
}