Represent the given number as the sum of two composite numbers Last Updated : 10 Mar, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report 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; } 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 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 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 JavaScript <script> // javascript implementation of the approach // Function to find two composite // numbers which when added // give sum as n function findNums(n) { // Only 8 and 10 can be represented // as the sum of two composite integers if (n <= 11) { if (n == 8) document.write("4 4"); if (n == 10) document.write("4 6"); else document.write("-1"); return; } // If n is even if (n % 2 == 0) document.write("4 " + (n - 4)); // If n is odd else document.write("9 " + (n - 9)); } // Driver code var n = 13; findNums(n); // This code contributed by shikhasingrajput </script> Output: 9 4 Time Complexity: O(1) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Split N as the sum of K numbers satisfying the given conditions I IshwarGupta Follow Improve Article Tags : Mathematical DSA Numbers Practice Tags : MathematicalNumbers Similar Reads Check if given number can be represented as sum of two great numbers We are given a number N. We need to check if the given number N can be represented as sum of two Great numbers. If yes then print those two great numbers else print no. Great numbers are those which are represented in the form : ((b)*(b+1)*(2*b+1))/6 where b is a natural number. Examples: Input : N 7 min read Sum of all the Composite Numbers from Odd indices of the given array Given an array arr[] of size N which contains at least one composite number. The task is to find out the sum of all the composite numbers in the array which are at odd indices (where indexing is 1 based). Examples: Input: arr = [13, 5, 8, 16, 25] Output: 33 Explanation: The number in the odd indices 6 min read Split N as the sum of K numbers satisfying the given conditions Given an integer N, the task is to express the given number as the sum of K numbers where at least K - 1 numbers are distinct and are product of 2 primes. If no possible answer, exists, print -1. Examples: Input: N = 52, K = 5 Output: 6 10 14 15 7 Explanation: N = 52 can be expressed as 6 10 14 15 2 9 min read Find the maximum number of composite summands of a number Given an integer N(1<=N<=10^9). The task is to represent N as a sum of the maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. There can be multiple queries Examples: Input : 12 Output : 3 Explanation : 12 can be written ha 8 min read Sum of all composite numbers lying in the range [L, R] for Q queries Given Q queries in the form of 2D array arr[][] whose every row consists of two numbers L and R which denotes the range [L, R], the task is to find the sum of all Composite Numbers lying in range [L, R]. Input: arr[][] = {{10, 13}, {12, 21}} Output: 22 116 Explanation: From 10 to 13 only 10 and 12 i 10 min read Check if a prime number can be expressed as sum of two Prime Numbers Given a number n, the task is to check if it is possible to express n as the sum of two prime numbers, a and b. If such pair does not exist, return [-1, -1].Note: If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then [a, b] is considered as our an 9 min read Like