🧮

Least Common Multiple

Least Common Multiple
쉬움 ģ•Œź³ ė¦¬ģ¦˜ +10pts

Problem

Write a function that returns the least common multiple of two numbers.

Examples

Input: lcm(4, 6)
Output: 12

Explanation

ģ“ ė¬øģ œėŠ” **GCD넼 ķ™œģš©**ķ•˜ģ—¬ ģµœģ†Œź³µė°°ģˆ˜ė„¼ źµ¬ķ•˜ėŠ” ė°©ė²•ģ„ ķ•™ģŠµķ•©ė‹ˆė‹¤. ## 핵심 ź°œė…: ģµœģ†Œź³µė°°ģˆ˜ (LCM) ģµœģ†Œź³µė°°ģˆ˜ėŠ” 두 ģˆ˜ģ˜ ź³µķ†µėœ 배수 중 ź°€ģž„ ģž‘ģ€ ģˆ˜ģž…ė‹ˆė‹¤. ### GCD와 LCMģ˜ ꓀계 ```javascript LCM(a, b) = (a * b) / GCD(a, b) ``` ### ģ ‘ź·¼ 방법 ```javascript function lcm(a, b) { const gcd = (x, y) => y ? gcd(y, x % y) : x; return (a * b) / gcd(a, b); } ``` ###...

View detailed explanation →

Key Concepts

ģµœģ†Œź³µė°°ģˆ˜ GCD ķ™œģš© ģˆ˜ķ•™ ź³µģ‹ ģ˜¤ė²„ķ”Œė”œģš° ė°©ģ§€
Time: O(log(min(a,b))) Space: O(1)
solution.js
Ctrl + Enter
Run tests to see results here.