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 email@example.com. 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find the XOR of first N Prime Numbers
- Find three prime numbers with given sum
- Find the Product of first N Prime Numbers
- Program to find sum of prime numbers between 1 to n
- Find the sum of prime numbers in the Kth array
- Find count of Almost Prime numbers from 1 to N
- Program to find the LCM of two prime numbers
- Find out the prime numbers in the form of A+nB or B+nA
- Find product of prime numbers between 1 to n
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- C/C++ Program to find Prime Numbers between given range
- Program to find Prime Numbers Between given Interval
- Find all the prime numbers of given number of digits
- Find two distinct prime numbers with given product
- Find a sequence of N prime numbers whose sum is a composite number
- Find the prime numbers which can written as sum of most consecutive primes
- 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
- Find the highest occurring digit in prime numbers in a range
- Print the nearest prime number formed by adding prime numbers to N