![]() |
VOOZH | about |
Given an array arr[] of size N, the task is to find the minimum LCM (Least Common Multiple) of all unique pairs in the given array, where 1 <= N <= 105, 1 <= arr[i] <= 105.
Examples:
Input: arr[] = {2, 4, 3}
Output: 4
Explanation
LCM (2, 4) = 4
LCM (2, 3) = 6
LCM (4, 3) = 12
Minimum possible LCM is 4.Input: arr [] ={1, 5, 2, 2, 6}
Output: 2
Naive Approach
Below is the implementation of the above approach:
4
Time Complexity: O(N2)
Auxiliary Space: O(log(Ai)), where Ai is the second maximum element in the array.
Efficient Approach: This approach depends upon the formula:
Product of two number = LCM of two number * GCD of two number
Below is the implementation of the above approach:
4
Time Complexity: O((N + M) * log(M))
Auxiliary Space: O(M) where M is the maximum element in the array.