Problem 161851 · medium · Phase 01 Prerequisites & Setup

Trailing Zeros of a Factorial

functions · factorials · loops

Write trailing_zeros(n) that returns how many zeros n! (n factorial) ends with. For example 10! = 3628800 ends with two zeros.

Do not build the factorial itself: for the largest inputs it would have hundreds of millions of digits.

Examples

Input:  n = 5
Output: 1

Input:  n = 10
Output: 2

Input:  n = 25
Output: 6

Constraints

  • 0 <= n <= 10**9

Goals

  • Reason about where trailing zeros come from
  • Avoid computing a huge factorial at all
Starting Python…