#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
namespace AOJ0185
{
	class Primes
	{
	public:
		static void GetPrimes(int max, vector<int> &primes)
		{
			vector<bool> flags(max + 1, true);
			for (int i = 2; i <= max; i++)
			{
				if (flags[i])
				{
					primes.push_back(i);
					for (int j = i; j <= max; j += i)
					{
						flags[j] = false;
					}
				}
			}
		}
	};

	class Solver
	{
	private:
		static const int MAX_N = 1000001;
		int Input()
		{
			int n;
			cin >> n;
			return n;
		}

		void Output(int answer)
		{
			cout << answer << endl;
		}

	public:
		void Solve()
		{
			vector<int> primes;
			Primes::GetPrimes(MAX_N, primes);

			int n;
			while (n = Input())
			{
				int answer = 0;
				for (int i = 0; i < primes.size(); i++)
				{
					int diff = n - primes[i];
					if (diff < primes[i])break;
					bool exist = binary_search(primes.begin(), primes.end(), diff);
					if (exist)answer++;
				}
				Output(answer);
			}
		}

	};
}

int main()
{
	AOJ0185::Solver().Solve();
}

