#C10539. Sum of Two Primes
Sum of Two Primes
Sum of Two Primes
Given a positive integer \(N\), determine whether it can be expressed as the sum of two prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The smallest possible sum of two primes is \(2 + 2 = 4\).
If such a pair exists, output the two primes in ascending order (i.e. sorted order). If multiple answers are possible, output the first valid pair found. If no such representation exists, output -1
.
For example:
- For \(N = 10\), one solution is \(3 + 7 = 10\), so the answer is
3 7
. - For \(N = 16\), one solution is \(3 + 13 = 16\); note that another correct answer would be
5 11
, but the program should output the first valid pair found. - For \(N = 11\) there is no way to write it as a sum of two primes, so the output is
-1
.
inputFormat
The input is read from standard input and consists of a single integer \(N\) on one line.
outputFormat
If a valid pair of primes \(p\) and \(q\) exists with \(p + q = N\), output them as two space-separated integers in ascending order on one line. Otherwise, output -1
.
10
3 7