Given an integer N, the task is to find three prime numbers X, Y and Z such that the sum of these three numbers is equal to N i.e. X + Y + Z = N.
Input: N = 20
Output: 2 5 13
Input: N = 34
Output: 2 3 29
- Generate prime numbers using Sieve of Eratosthenes
- Start from the first prime number.
- Take another number from the generated list.
- Subtract first number and second number from the original number to obtain the third number.
- Check if the third number is a prime number.
- If the third number is a prime number then output the three numbers.
- Otherwise, repeat the process for the second number and consequently the first number
- If the answer does not exist then print -1.
Below is the implementation of the above approach:
2 2 97
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 two prime numbers with given sum
- Find the XOR of first N Prime Numbers
- Find the Product of first N Prime Numbers
- Find count of Almost Prime numbers from 1 to N
- Program to find the LCM of two prime numbers
- Find product of prime numbers between 1 to n
- Program to find sum of prime numbers between 1 to n
- Find the sum of prime numbers in the Kth array
- Find out the prime numbers in the form of A+nB or B+nA
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Program to find Prime Numbers Between given Interval
- Find two distinct prime numbers with given product
- Find all the prime numbers of given number of digits
- 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
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : AnkitRai01