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
- 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 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 coordinates of a prime number in a Prime Spiral
- Find two prime numbers with given sum
- Find the XOR of first N Prime Numbers
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Find the sum of prime numbers in the Kth 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.