Given a positive integer N > 1, the task is to find the maximum LCM among all the pairs (i, j) such that i < j ≤ N.
Input: N = 3
LCM(1, 2) = 2
LCM(1, 3) = 3
LCM(2, 3) = 6
Input: N = 4
Approach: Since the LCM of two consecutive elements is equal to their multiples then it is obvious that the maximum LCM will be of the pair (N, N – 1) i.e. (N * (N – 1)).
Below is the implementation of the above approach:
Time Complexity: O(1)
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.