Created
March 28, 2020 22:30
-
-
Save raphaelvallat/69373e43d55d7d1dec688b16ca719a1d to your computer and use it in GitHub Desktop.
Least common multiple of a range of numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import numpy as np | |
for k in range(2, 21): | |
digits = range(1, k) | |
i = abs(functools.reduce(np.lcm, digits)) | |
print(f"The least common multiple of {digits} is {i}") | |
# Output: | |
# The least common multiple of range(1, 2) is 1 | |
# The least common multiple of range(1, 3) is 2 | |
# The least common multiple of range(1, 4) is 6 | |
# The least common multiple of range(1, 5) is 12 | |
# The least common multiple of range(1, 6) is 60 | |
# The least common multiple of range(1, 7) is 60 | |
# The least common multiple of range(1, 8) is 420 | |
# The least common multiple of range(1, 9) is 840 | |
# The least common multiple of range(1, 10) is 2520 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment