Pretty Average Primes
InterviewTime limit1sMemory limit512 MB
For each N, print two primes whose average is N, which means finding a prime pair that sums to 2N.
- Level
Medium5 of 10
- Topics
- Number theory, Brute force, Math, Implementation
- Solved
- No attempts yet
Problem
For various given positive integers , find two primes, and , such that is the average (mean) of and . That is, should be equal to .
Recall that a prime number is an integer which is only divisible by 1 and . For example, 2, 3, 5, 7, 11 are the first few primes, and 4, 6, 8, 9 are not prime numbers.
Input
The first line of input is the number (), which is the number of test cases. Each of the next lines contain one integer (, ).
For 6 of the available 15 marks, all .
Output
The output will consist of lines. The th line of output will contain two integers, and , separated by one space. It should be the case that and that and are prime numbers.
If there are more than one possible and for a particular , output any such pair. The order of the pair and does not matter.
It will be the case that there will always be at least one set of values and for any given .
Hint
You may have heard about Goldbach's conjecture, which states that every even integer greater than 2 can be expressed as the sum of two prime numbers. There is no known proof, yet, so if you want to be famous, prove that conjecture (after you finish the CCC).
This problem can be used to help verify that conjecture, since every even integer can be written as , and your task is to find two primes and such that .