# Represent the given number as the sum of two composite numbers

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**.

**Examples:**

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:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find two composite ` `// numbers which when added ` `// give sum as n ` `void` `findNums(` `int` `n) ` `{ ` ` ` ` ` `// Only 8 and 10 can be represented ` ` ` `// as the sum of two composite integers ` ` ` `if` `(n <= 11) { ` ` ` `if` `(n == 8) ` ` ` `cout << ` `"4 4"` `; ` ` ` `if` `(n == 10) ` ` ` `cout << ` `"4 6"` `; ` ` ` `else` ` ` `cout << ` `"-1"` `; ` ` ` `return` `; ` ` ` `} ` ` ` ` ` `// If n is even ` ` ` `if` `(n % 2 == 0) ` ` ` `cout << ` `"4 "` `<< (n - 4); ` ` ` ` ` `// If n is odd ` ` ` `else` ` ` `cout << ` `"9 "` `<< (n - 9); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 13; ` ` ` ` ` `findNums(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG ` `{ ` ` ` `// Function to find two composite ` `// numbers which when added ` `// give sum as n ` `static` `void` `findNums(` `int` `n) ` `{ ` ` ` ` ` `// Only 8 and 10 can be represented ` ` ` `// as the sum of two composite integers ` ` ` `if` `(n <= ` `11` `) ` ` ` `{ ` ` ` `if` `(n == ` `8` `) ` ` ` `System.out.print(` `"4 4"` `); ` ` ` `if` `(n == ` `10` `) ` ` ` `System.out.print(` `"4 6"` `); ` ` ` `else` ` ` `System.out.print(` `"-1"` `); ` ` ` `return` `; ` ` ` `} ` ` ` ` ` `// If n is even ` ` ` `if` `(n % ` `2` `== ` `0` `) ` ` ` `System.out.print(` `"4 "` `+ (n - ` `4` `)); ` ` ` ` ` `// If n is odd ` ` ` `else` ` ` `System.out.print(` `"9 "` `+ (n - ` `9` `)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String args[]) ` `{ ` ` ` `int` `n = ` `13` `; ` ` ` ` ` `findNums(n); ` `} ` `} ` ` ` `// This code is contributed by andrew1234 ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to find two composite ` `# numbers which when added ` `# give sum as n ` `def` `findNums(n): ` ` ` ` ` `# Only 8 and 10 can be represented ` ` ` `# as the sum of two composite integers ` ` ` `if` `(n <` `=` `11` `): ` ` ` `if` `(n ` `=` `=` `8` `): ` ` ` `print` `(` `"4 4"` `, end ` `=` `" "` `) ` ` ` `if` `(n ` `=` `=` `10` `): ` ` ` `print` `(` `"4 6"` `, end ` `=` `" "` `) ` ` ` `else` `: ` ` ` `print` `(` `"-1"` `, end ` `=` `" "` `) ` ` ` ` ` `# If n is even ` ` ` `if` `(n ` `%` `2` `=` `=` `0` `): ` ` ` `print` `(` `"4 "` `, (n ` `-` `4` `), end ` `=` `" "` `) ` ` ` ` ` `# If n is odd ` ` ` `else` `: ` ` ` `print` `(` `"9 "` `, n ` `-` `9` `, end ` `=` `" "` `) ` ` ` `# Driver code ` `n ` `=` `13` ` ` `findNums(n) ` ` ` `# This code is contributed by Mohit Kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to find two composite ` ` ` `// numbers which when added ` ` ` `// give sum as n ` ` ` `static` `void` `findNums(` `int` `n) ` ` ` `{ ` ` ` ` ` `// Only 8 and 10 can be represented ` ` ` `// as the sum of two composite integers ` ` ` `if` `(n <= 11) ` ` ` `{ ` ` ` `if` `(n == 8) ` ` ` `Console.Write(` `"4 4"` `); ` ` ` `if` `(n == 10) ` ` ` `Console.Write(` `"4 6"` `); ` ` ` `else` ` ` `Console.Write(` `"-1"` `); ` ` ` `return` `; ` ` ` `} ` ` ` ` ` `// If n is even ` ` ` `if` `(n % 2 == 0) ` ` ` `Console.Write(` `"4 "` `+ (n - 4)); ` ` ` ` ` `// If n is odd ` ` ` `else` ` ` `Console.Write(` `"9 "` `+ (n - 9)); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `n = 13; ` ` ` ` ` `findNums(n); ` ` ` `} ` `} ` ` ` `// This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

**Output:**

9 4

## Recommended Posts:

- Represent a number as sum of minimum possible psuedobinary numbers
- Find a sequence of N prime numbers whose sum is a composite number
- Composite numbers with digit sum 1
- Split n into maximum composite numbers
- Find two Composite Numbers such that there difference is N
- Product of all the Composite Numbers in an array
- Find a range of composite numbers of given length
- Sum and Product of all Composite numbers which are divisible by k in an array
- Sum and product of k smallest and k largest composite numbers in the array
- Represent the fraction of two numbers in the string format
- 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
- Find the total number of composite factor for a given number
- Find the maximum number of composite summands of a number
- Composite Number

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.