Given an integer X, the task is to find two integers A and B such that LCM(A, B) = X and the difference between the A and B is minimum possible.
Input: X = 6
Output: 2 3
LCM(2, 3) = 6 and (3 – 2) = 1
which is the minimum possible.
Input X = 7
Output: 1 7
Approach: An approach to solve this problem is to find all the factors of the given number using the approach discussed in this article and then find the pair (A, B) that satisfies the given conditions and has the minimum possible difference.
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.
- Sum of LCM(1, n), LCM(2, n), LCM(3, n), ... , LCM(n, n)
- Minimum replacement of pairs by their LCM required to reduce given array to its LCM
- Find two numbers with given sum and maximum possible LCM
- Minimum LCM and GCD possible among all possible sub-arrays
- Given GCD G and LCM L, find number of possible pairs (a, b)
- Find two distinct numbers such that their LCM lies in given range
- Minimum possible value of max(A, B) such that LCM(A, B) = C
- Program to find LCM of two numbers
- Program to find LCM of two Fibonnaci Numbers
- Program to find the LCM of two prime numbers
- Count of all possible pairs having sum of LCM and GCD equal to N
- Finding LCM of more than two (or array) numbers without using GCD
- LCM of two large numbers
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Find minimum possible values of A, B and C when two of the (A + B), (A + C) and (B + C) are given
- Find the pair (a, b) with minimum LCM such that their sum is equal to N
- Minimum LCM of all pairs in a given array
- Find LCM of rational numbers
- Program to find LCM of 2 numbers without using GCD
- Count ordered pairs of numbers with a given LCM
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.