Skip to content

Factorial Trailing Zeroes

MediumBit Manipulation & Math
Decode it first. Clues, constraints, pattern and plan before any code.

Return how many trailing zeros n! has (n! = n · (n - 1) · ... · 2 · 1). Can you do it in logarithmic time, without computing the factorial?

n = 3   →  0   (3! = 6)
n = 5   →  1   (5! = 120)
n = 25  →  6

Constraints

  • 0 <= n <= 10^4