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.
- Calculate the GCD using the iterative loop (from the previous mission).
- Use the formula to find the LCM.
- Print the final LCM value.
01EXAMPLE 1
Input
a=12, b=15Output
60Explanation: 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
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
a12
b15
Expected Output
60
Click RUN to test your solution