The LCM Link

MediumAcc. 91.7%
+25 XP 10

Harmonizing Cycles

The Least Common Multiple (LCM) is the smallest positive integer that is divisible by both a and b. Formula: $LCM(a, b) = |a imes b| / GCD(a, b)$.

The Assignment

Your function receives parameters a and b.

  1. Calculate the GCD using the iterative loop (from the previous mission).
  2. Use the formula to find the LCM.
  3. Print the final LCM value.

01EXAMPLE 1

Inputa=12, b=15
Output60

Explanation: Multiples of 12: 12, 24, 36, 48, 60... Multiples of 15: 15, 30, 45, 60... 60 is the first match.

Constraints

  • Implement GCD iterative logic inside.
  • Handle inputs correctly to avoid division by zero.
MathLoops
JavaScript
Loading...
3 Hidden

Input Arguments

a12
b15

Expected Output

60

Click RUN to test your solution