给定数字N ,任务是找到两个复合数字X和Y ,以使它们之间的差等于N。请注意,此任务可以有多个答案。打印其中任何一个。
例子:
Input: N = 4
Output: X = 36, Y = 32
Input: N = 1
Output: X = 9, Y = 8
方法:
- 我们必须找到X – Y = N。
- 我们知道, N的最小值可以是0或1 。如果它是0 ,那么我们可以将任何一个复合数字打印两次。
- 如果N = 0 ,那么我们可以打印9 * N和8 * N ,因为这些复合数字之间的差异最小,即1 。
- 我们还可以打印15 * N和16 * N ,但是我们必须打印任何两个复合数字,因此这些数字都是可能的。
下面是实现
C++
#include
using namespace std;
// C++ code to Find two Composite Numbers
// such that there difference is N
// Function to find the two composite numbers
void find_composite_nos(int n)
{
cout << 9 * n << " " << 8 * n;
}
// Driver code
int main()
{
int n = 4;
find_composite_nos(n);
return 0;
}
Java
// Java code to Find two Composite Numbers
// such that there difference is N
class GFG
{
// Function to find the two composite numbers
static void find_composite_nos(int n)
{
System.out.println(9 * n + " " + 8 * n);
}
// Driver code
public static void main (String[] args)
{
int n = 4;
find_composite_nos(n);
}
}
// This code is contributed by AnkitRai01
Python3
# Python3 code to Find two Composite Numbers
# such that their difference is N
# Function to find the two composite numbers
def find_composite_nos(n) :
print(9 * n, 8 * n);
# Driver code
if __name__ == "__main__" :
n = 4;
find_composite_nos(n);
# This code is contributed by AnkitRai01
C#
// C# code to Find two Composite Numbers
// such that there difference is N
using System;
class GFG
{
// Function to find the two composite numbers
static void find_composite_nos(int n)
{
Console.WriteLine(9 * n + " " + 8 * n);
}
// Driver code
public static void Main()
{
int n = 4;
find_composite_nos(n);
}
}
// This code is contributed by AnkitRai01
Javascript
输出:
36 32