#793
Preimage Size of Factorial Zeroes Function
candidate master · 1535 · lc hard +32 · verified · 46.7% accepted · 471 likes · top 31%
Description
Define f(x) as the number of trailing zeroes in x!, where x! = 1 * 2 * 3 * ... * x and 0! = 1 by convention.
- As examples, f(3) = 0 because 3! = 6 has no trailing zeroes, and f(11) = 2 because 11! = 39916800 ends in two zeroes.
Given an integer k, return the count of non-negative integers x for which f(x) = k.
Example 1:
Input: k = 0
Output: 5
Explanation: 0!, 1!, 2!, 3!, and 4! end with k = 0 zeroes.
Example 2:
Input: k = 5
Output: 0
Explanation: There is no x such that x! ends in k = 5 zeroes.
Example 3:
Input: k = 3
Output: 5
Code
1
2
3