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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Check if a prime number can be expressed as sum of two Prime Numbers
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Count all prime numbers in a given range whose sum of digits is also prime
- Absolute difference between the Product 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
- Prime numbers after prime P with sum S
- Print prime numbers with prime sum of digits in an array
- Sum of prime numbers without odd prime digits
- Count numbers in a given range whose count of prime factors is a Prime Number
- Bitwise AND of the sum of prime numbers and the sum of composite numbers in an array
- Find two distinct prime numbers with given product
- Find all numbers between range L to R such that sum of digit and sum of square of digit is prime
- Numbers less than N which are product of exactly two distinct prime numbers
- Find three prime numbers with given sum
- Print the nearest prime number formed by adding prime numbers to N
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Permutation of first N positive integers such that prime numbers are at prime indices