Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: What is the smallest positive integer that is divisible by every integer from 1 to 12? Run the code.

Problem: What is the smallest positive integer that is divisible by every integer from 1 to 12? Run the code.
from math import lcm
print(lcm(*range(1, 13)))
What is printed?
  1. A. 2310
  2. B. 4620
  3. C. 27720
  4. D. 13860

Correct answer: C. 27720

lcm(1..12) = 2³ · 3² · 5 · 7 · 11 = 27720. Multiplying only the primes gives 2310, using 2² · 3 gives 4620, and missing the 2³ from 8 gives 13860.

More Coding Interview Problems questions

Exams that ask this topic