Given a prime number . The task is to check if it is possible to express as sum of two separate prime numbers.
Note: The range of N is less than 108.
Input : N = 13 Output : Yes Explanation : The number 13 can be written as 11 + 2, here 11 and 2 are both prime. Input : N = 11 Output : No
Simple Solution: A simple solution is to create a sieve to store all the prime numbers less than the number N. Then run a loop from 1 to N and check whether and are both prime or not. If yes then print Yes, else No.
Efficient solution: Apart from 2, all of the prime numbers are odd. So it is not possible to represent a prime number (which is odd) to be written as a sum of two odd prime numbers, so we are sure that one of the two prime number should be 2. So we have to check whether n-2 is prime or not. If it holds we print Yes else No.
For example, if the number is 19 then we have to check whether 19-2 = 17 is a prime number or not. If 17 is a prime number then print yes otherwise print no.
Below is the implementation of the above approach:
- N expressed as sum of 4 prime numbers
- Print the nearest prime number formed by adding prime numbers to N
- Check if a number can be written as a sum of 'k' prime numbers
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Quick ways to check for Prime and find next Prime in Java
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Print prime numbers with prime sum of digits in an array
- Check if a number can be expressed as sum two abundant numbers
- Check if a number can be expressed as a sum of consecutive numbers
- Check whether the sum of prime elements of the array is prime or not
- Check if two numbers are co-prime or not
- Check whether the given numbers are Cousin prime or not
- Check whether a number can be expressed as a product of single digit numbers
- Find coordinates of a prime number in a Prime Spiral
- Check if product of array containing prime numbers is a perfect square
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.