Given an integer N, the task is to represent N as the sum of two composite integers. There can be multiple ways possible, print any one of them. If it is not possible to represent the number as the sum of two composite numbers then print -1.
Input: N = 13
Output: 4 9
4 + 9 = 13 and both 4 and 9 are composite.
Input: N = 18
Output: 4 14
Approach: When N ≤ 11 then only 8 and 10 are the integers which can be represented as the sum of two composite integers i.e. 4 + 4 and 4 + 6 respectively.
When N > 11 then there are two cases:
- When N is even: N can be represented as 4 + (N – 4) since both are composite.
- When N is odd: N can be represented as 9 + (N – 9).
Below is the implementation of the above approach:
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.
- Find a sequence of N prime numbers whose sum is a composite number
- Represent a number as sum of minimum possible psuedobinary numbers
- Highly Composite Numbers
- Composite numbers with digit sum 1
- Product of all the Composite Numbers in an array
- Split n into maximum composite numbers
- Find two Composite Numbers such that there difference is N
- Represent N as sum of K even numbers
- Represent K^N as the sum of exactly N numbers
- Find a range of composite numbers of given length
- Sum of all composite numbers lying in the range [L, R] for Q queries
- Sum and Product of all Composite numbers which are divisible by k in an array
- Represent K as sum of N-bonacci numbers
- Sum and product of k smallest and k largest composite numbers in the array
- Represent N as sum of K odd numbers with repetitions allowed
- Represent N as sum of K even or K odd numbers with repetitions allowed
- Generate a list of n consecutive composite numbers (An interesting method)
- Queries for the difference between the count of composite and prime numbers in a given range
- Represent the fraction of two numbers in the string format
- Minimum count of numbers required from given array to represent S
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.