Given an even number (greater than 2 ), print two prime numbers whose sum will be equal to given number. There may be several combinations possible. Print only first such pair.
An interesting point is, a solution always exist according to Goldbach’s conjecture.
Input: n = 74 Output: 3 71 Input : n = 1024 Output: 3 1021 Input: n = 66 Output: 5 61 Input: n = 9990 Output: 17 9973
The idea is to find all the primes less than or equal to the given number N using Sieve of Eratosthenes. Once we have an array that tells all primes, we can traverse through this array to find pair with given sum.
This article is contributed by Rakesh Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find the XOR of first N Prime Numbers
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Find out the prime numbers in the form of A+nB or B+nA
- Program to find sum of prime numbers between 1 to n
- Find the sum of prime numbers in the Kth array
- Find the Product of first N Prime Numbers
- Find product of prime numbers between 1 to n
- Find count of Almost Prime numbers from 1 to N
- Find all the prime numbers of given number of digits
- Find two distinct prime numbers with given product
- Program to find Prime Numbers Between given Interval
- Find the prime numbers which can written as sum of most consecutive primes
- Find a sequence of N prime numbers whose sum is a composite number
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array