The Problem
Find the LCM of the given array of positive numbers.
The LCM (Least Common Multiple) of two or more numbers is the smallest number that is evenly divisible by all numbers in the set.
Examples
Input: arr[] = {1, 2, 3, 4, 8, 28, 36}Output: 504Input: arr[] = {16, 18, 20, 30}Output: 720
We have explored 2 approaches:
Method 1 (using GCD)Method 2 (without using GCD)Method 1 (using GCD)
We know that,
LCM(a, b) = (a*b)/GCD(a, b), where GCD stands for Greatest Common Divisor.
The ab...
Published on May 31, 2021 13:18