class Solution:
def preimageSizeFZF(self, k: int) -> int:
left = 0
right = 5 * (k + 1)
#Calculating the minimum n that satisfies f(n) = k
while left < right:
else:
right = mid
#Calculating the minimum n that satisfies f(n) = k + 1.
# Let m be the minimum m that satisfies f(m) = k + 1
#Let n be the minimum n that satisfies f(n) = k
#Let max_n be the maximum n that satisfies f(n) = k
# m = max_n + 1
#The number of integers between n and max_n is max_n - n + 1
#Thus, m - n = max_n - n + 1
left1 = 0
right1 = 5*(k+2)
while left1 < right1:
mid1 = left1 + (right1 - left1)//2
if Solution.numtrailingzeroes(mid1) < k + 1:
left1 = mid1 + 1
else:
right1 = mid1
return left1 - left
def numtrailingzeroes(n):
ct = 0
while n > 0:
n //= 5
ct += n
return ct