Skip to content

Instantly share code, notes, and snippets.

@raphaelvallat
Created March 28, 2020 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raphaelvallat/69373e43d55d7d1dec688b16ca719a1d to your computer and use it in GitHub Desktop.
Save raphaelvallat/69373e43d55d7d1dec688b16ca719a1d to your computer and use it in GitHub Desktop.
Least common multiple of a range of numbers
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