Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: How many divisors does 10^6 have? Run the code.

Problem: How many divisors does 10^6 have? Run the code.
print(sum(1 for d in range(1, 10 ** 6 + 1) if (10 ** 6) % d == 0))
What is printed?
  1. A. 36
  2. B. 49
  3. C. 13
  4. D. 7

Correct answer: B. 49

10⁶ = 2⁶ · 5⁶, so d = (6 + 1)(6 + 1) = 49. Forgetting the + 1 gives 36, adding the exponents gives 13, and 7 counts only powers of 10.

More Coding Interview Problems questions

Exams that ask this topic