#include<vector>
#include<iostream>
using namespace std;
namespace AOJ0185
{
	class Primes
	{
	private:
		vector<int> primes;

	public:
		Primes(int max)
		{
			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;
					}
				}
			}
		}

		int operator[](int index)
		{
			return primes[index];
		}

		int size()
		{
			return primes.size();
		}
	};

	class Solver
	{
	private:
		static const int MAX_N = 1000001;
		int answers[MAX_N] = {};
		void CalcAnswers()
		{
			Primes primes(MAX_N);
			for (int i = 0; i < primes.size(); i++)
			{
				for (int j = i; j < primes.size(); j++)
				{
					int sum = primes[i] + primes[j];
					if (sum >= MAX_N)break;
					answers[sum]++;
				}
			}
		}

		int Input()
		{
			int n;
			cin >> n;
			return n;
		}

		void Output(int n)
		{
			cout << answers[n] << endl;
		}

	public:
		void Solve()
		{
			CalcAnswers();
			int n;
			while (n = Input())Output(n);
		}
	};
}

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

