Tutte le sfide
Facile 0 risolte 0% di accettazione

Least Common Multiple

Find the smallest positive number divisible by both values.

Return the least common multiple of a and b, the smallest positive number that both divide. lcm(a, b) = a / gcd(a, b) × b.

Implement lcm(a, b).

Input

a: The first positive number. b: The second positive number.

Output

Return lcm(a, b).

Vincoli

1 ≤ a, b ≤ 1,000,000,000

Esempi

Esempio 1
Input:
a = 4
b = 6

Output atteso:
expected = 12
Input:
long long a = 4;
long long b = 6;

Output atteso:
long long expected = 12;
Input:
long a = 4;
long b = 6;

Output atteso:
long expected = 12;

Spiegazione

Multiples of 4: 4, 8, 12…; multiples of 6: 6, 12…; the first common one is 12.

Esempio 2
Input:
a = 7
b = 7

Output atteso:
expected = 7
Input:
long long a = 7;
long long b = 7;

Output atteso:
long long expected = 7;
Input:
long a = 7;
long b = 7;

Output atteso:
long expected = 7;

Spiegazione

A number's LCM with itself is the number: 7.

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.