![]() |
VOOZH | about |
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.
Examples:
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:
3 4
Time Complexity: O(n1/2 * log(max(a, b)))
Auxiliary Space: O(log(max(a, b)))