Data Structures & AlgorithmsModerateTCS NQT · number theory

Problem: What does the following print?

Problem: What does the following print?
from math import lcm
print(lcm(*range(1, 11)))
  1. A. 3628800
  2. B. 5040
  3. C. 2520
  4. D. 720

Correct answer: C. 2520

The LCM of 1..10 takes the highest power of each prime up to 10: 2^3 * 3^2 * 5 * 7 = 2520. The product 10! = 3628800 is the trap of multiplying instead.

More Coding Interview Problems questions

Exams that ask this topic