Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

What is the smallest positive integer x such that x! (x factorial) ends with at least 1000 zeros?

  1. A. 4000
  2. B. 4005
  3. C. 4010
  4. D. 200

Correct answer: B. 4005

The number of trailing zeros of x! is Σ ⌊x / 5ᵏ⌋, which is non-decreasing in x, so binary search finds the first x that reaches N. Dividing N by 5 counts only one term of the sum.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic