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
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.
- Sum of prime numbers without odd prime digits
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- 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
- Check if a prime number can be expressed as sum of two Prime Numbers
- Express a number as sum of consecutive numbers
- Count ways to express a number as sum of consecutive numbers
- Count ways to express a number as sum of exactly two numbers
- 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
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime
- Average of odd numbers till a given odd number
- Prime numbers after prime P with sum S
- Print prime numbers with prime sum of digits in an array
- Count all prime numbers in a given range whose sum of digits is also prime
- Bitwise AND of the sum of prime numbers and the sum of composite numbers in an array
- 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
- Count numbers in a given range whose count of prime factors is a Prime Number
- Minimum numbers needed to express every integer below N as a sum
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jit_t