Problem 550
Goldbach Partitions
Problem
Goldbach's conjecture says every even number greater than 2 is a sum of two primes. Given an even number N, count the ways to write it as p + q where p and q are primes and p <= q. Order does not matter, so 3 + 7 and 7 + 3 are the same way, but 5 + 5 is allowed. Sieve the primes up to N and check every prime p up to N / 2.
Input
A single even integer N.
Output
Print the number of ways to write N as a sum of two primes p <= q.
Constraints
4 <= N <= 1000000; N is even
Example input
10
Example output
2
Explanation
10 can be written as 3 + 7 or as 5 + 5. The other splits, like 1 + 9 or 2 + 8, use a number that is not prime, so the answer is 2.