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:
1
💡 Note:
Only f(0) = 0, since 0! = 1 has no trailing zeros. All other factorials have trailing zeros.
Example 3 — Impossible Value
$
Input:
k = 4
›
Output:
0
💡 Note:
No factorial has exactly 4 trailing zeros. The count jumps from 3 to 7, skipping 4,5,6.
Constraints
- 0 ≤ k ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input k
Target number of trailing zeros
2
Search Pattern
f(x) increases but skips values
3
Count Results
Return 0, 1, or 5
Key Takeaway
🎯 Key Insight: Factorial trailing zeros have gaps - some counts are impossible, others appear exactly 5 times consecutively!
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code