Skip to main content
LeetCode 793, Hard. Topics: Math, Binary Search. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 28 parametrized pytest cases, and a playground notebook:

Problem

Let <code>f(x)</code> be the number of zeroes at the end of <code>x!</code>. Recall that <code>x! = 1 * 2 * 3 * … * x</code> and by convention, <code>0! = 1</code>. <ul> <li>For example, <code>f(3) = 0</code> because <code>3! = 6</code> has no zeroes at the end, while <code>f(11) = 2</code> because <code>11! = 39916800</code> has two zeroes at the end.</li> </ul> <p>Given an integer <code>k</code>, return <em>the number of non-negative integers</em> <code>x</code> <em>have the property that</em> <code>f(x) = k</code>.</p>

Examples

Constraints

  • 0 <= k <= 10^9

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026