Given an integer N and the task is to find a sequence of N prime numbers whose sum is a composite number.
Input: N = 5
Output: 2 3 5 7 11
2 + 3 + 5 + 7 + 11 = 28 which is composite.
Input: N = 6
Output: 3 5 7 11 13 17
Approach: The sum of two prime numbers is always even which is composite as they are odd numbers except 2. There are two cases now,
- When N is even then we can print any N prime numbers except 2 and their sum will always be even i.e. odd numbers when added even number of times will give an even sum.
- When N is odd then we can print 2 and any other N – 1 primes to make sure that the sum is even. Since, N – 1 is even so the sum will be even for any primes except 2 then we add 2 as the Nth number to make sure that the sum remains even.
Below is the implementation of the above approach:
3 5 7 11 13 17
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Bitwise AND of the sum of prime numbers and the sum of composite numbers in an array
- XOR of K largest prime and composite numbers from the given array
- Queries for the difference between the count of composite and prime numbers in a given range
- Find all the prime numbers of given number of digits
- Find two Composite Numbers such that there difference is N
- Find a range of composite numbers of given length
- Represent the given number as the sum of two composite numbers
- Find the maximum number of composite summands of a number
- Find the total number of composite factor for a given number
- 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
- Find the largest composite number that divides N but is strictly lesser than N
- Find coordinates of a prime number in a Prime Spiral
- Find the K-th Permutation Sequence of first N natural 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.