Suppose we have a number n. We have to find smallest number m, such that factorial of m has at least n number of 0s.
So, if the input is like n = 2, then the output will be 10 because 10! = 3628800 and 9! = 362880, minimum number with 2 zeros is 10.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def count_fives(n): cnt = 0 while n > 0: n = n // 5 cnt += n return cnt def solve(n): left = 1 right = 5**24 while right - left > 5: mid = int((right + left) / 10) * 5 fives = count_fives(mid) if fives == n: right = mid left = right - 5 break elif fives < n: left = mid else: right = mid return right n = 2 print(solve(n))