Find two Composite Numbers such that there difference is N
Last Updated :
03 Mar, 2022
Given a number N, the task is to find two composite numbers X and Y, such that difference between them is equal to N. Note that there can be multiple answers for this task. Print any one of them.
Examples:
Input: N = 4
Output: X = 36, Y = 32
Input: N = 1
Output: X = 9, Y = 8
Approach:
- We have to find X – Y = N.
- We know, minimum value of N can be 0 or 1. If it is 0, then we can print any composite number twice.
- If N = 0, then we can print 9*N and 8 * N, because these composite numbers have minimum difference between each other, i.e., 1.
- We can also print 15 * N and 16 * N, but we have to print any two composite numbers, so any of these are possible.
Below is the implementation of the
C++
#include <bits/stdc++.h>
using namespace std;
void find_composite_nos( int n)
{
cout << 9 * n << " " << 8 * n;
}
int main()
{
int n = 4;
find_composite_nos(n);
return 0;
}
|
Java
class GFG
{
static void find_composite_nos( int n)
{
System.out.println( 9 * n + " " + 8 * n);
}
public static void main (String[] args)
{
int n = 4 ;
find_composite_nos(n);
}
}
|
Python3
def find_composite_nos(n) :
print ( 9 * n, 8 * n);
if __name__ = = "__main__" :
n = 4 ;
find_composite_nos(n);
|
C#
using System;
class GFG
{
static void find_composite_nos( int n)
{
Console.WriteLine(9 * n + " " + 8 * n);
}
public static void Main()
{
int n = 4;
find_composite_nos(n);
}
}
|
Javascript
<script>
function find_composite_nos(n)
{
document.write(9 * n + " " + 8 * n);
}
var n = 4;
find_composite_nos(n);
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...