Given an odd number, we need to express it as the sum of at most three prime numbers.
Input : 27 Output : 27 = 3 + 5 + 19 Input : 15 Output : 15 = 2 + 13
Approach : Here, we use Goldbach’s conjecture to solve this problem. It says that any even integer can be expressed as sum of two prime numbers.
We have three cases here:
1) When N is a prime number, print the number.
2) When (N-2) is a prime number, print 2 and N-2.
3) Express N as 3 + (N-3). Obviously, N-3 will be an even number (subtraction of an odd from another odd results in even). So, according to Goldbach’s conjecture, it can be expressed as the sum of two prime numbers. So, print 3 and other two prime numbers.
3 5 19
- Express a number as sum of consecutive numbers
- Count ways to express a number as sum of consecutive numbers
- Print the nearest prime number formed by adding prime numbers to N
- Check if a prime number can be expressed as sum of two Prime Numbers
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Represent a number as a sum of maximum possible number of Prime Numbers
- Largest number in [2, 3, .. n] which is co-prime with numbers in [2, 3, .. m]
- 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
- New Algorithm to Generate Prime Numbers from 1 to Nth Number
- Check if a number can be written as a sum of 'k' prime numbers
- Minimum numbers needed to express every integer below N as a sum
- Number of distinct prime factors of first n natural numbers
- Find a sequence of N prime numbers whose sum is a composite number
- Print prime numbers with prime sum of digits in an array
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 : jit_t