Preimage Size of Factorial Zeroes Function - Problem
Let f(x) be the number of zeroes at the end of x!. Recall that x! = 1 * 2 * 3 * ... * x and by convention, 0! = 1.
For example, f(3) = 0 because 3! = 6 has no zeroes at the end, while f(11) = 2 because 11! = 39916800 has two zeroes at the end.
Given an integer k, return the number of non-negative integers x have the property that f(x) = k.
Input & Output
Example 1 — Basic Case
$
Input:
k = 3
›
Output:
5
💡 Note:
f(15) = f(16) = f(17) = f(18) = f(19) = 3, so exactly 5 numbers give 3 trailing zeros
Example 2 — Special Case Zero
$
Input:
k = 0
›
Output:
5
💡 Note:
f(0) = f(1) = f(2) = f(3) = f(4) = 0, so exactly 5 numbers give 0 trailing zeros
Example 3 — Impossible Value
$
Input:
k = 4
›
Output:
5
💡 Note:
f(20) = f(21) = f(22) = f(23) = f(24) = 4, so exactly 5 numbers give 4 trailing zeros
Constraints
- 0 ≤ k ≤ 109
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code