dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.5 KiB
1.5 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 68ffb91507a5b645769328c6 | Challenge 103: LCM | 29 | challenge-103 |
--description--
Given two integers, return the least common multiple (LCM) of the two numbers.
The LCM of two numbers is the smallest positive integer that is a multiple of both numbers. For example, given 4 and 6, return 12 because:
- Multiples of
4are4,8,12and so on. - Multiples of
6are6,12,18and so on. 12is the smallest number that is a multiple of both.
--hints--
lcm(4, 6) should return 12.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(lcm(4, 6), 12)`)
}})
lcm(9, 6) should return 18.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(lcm(9, 6), 18)`)
}})
lcm(10, 100) should return 100.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(lcm(10, 100), 100)`)
}})
lcm(13, 17) should return 221.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(lcm(13, 17), 221)`)
}})
lcm(45, 70) should return 630.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(lcm(45, 70), 630)`)
}})
--seed--
--seed-contents--
def lcm(a, b):
return a
--solutions--
def lcm(a, b):
def gcd(x, y):
return x if y == 0 else gcd(y, x % y)
return abs(a * b) // gcd(a, b)