Data Structures & AlgorithmsModerateTCS NQT · ICPC regional

Problem: How many trailing zeros does 30! have in base 10?

  1. A. 6
  2. B. 3
  3. C. 7
  4. D. 26

Correct answer: C. 7

Legendre: 30 // 5 + 30 // 25 = 6 + 1 = 7, because 25 contributes two 5s. Counting multiples of 5 only gives 6, 30 // 10 gives 3, and 26 counts factors of 2, which are never the bottleneck.

More Coding Interview Problems questions

Exams that ask this topic