793. Preimage Size of Factorial Zeroes Function

网友投稿 569 2022-09-04

793. Preimage Size of Factorial Zeroes Function

793. Preimage Size of Factorial Zeroes Function

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 2 zeroes at the end. Given K, find how many non-negative integers x have the property that f(x) = K.

Example 1:Input: K = 0Output: 5Explanation: 0!, 1!, 2!, 3!, and 4! end with K = 0 zeroes.Example 2:Input: K = 5Output: 0Explanation: There is no x such that x! ends in K = 5

Note:

K will be an integer in the range [0, 10^9].

class Solution(object): def calcFactorial(self,v): n = v count = 0 while n > 0: count += n / 5 n = n / 5 return count def preimageSizeFZF(self, K): high = K*5 low = 0 while low <= high: mid = (high + low)/2 if self.calcFactorial(mid) < K: low = mid +1 elif self.calcFactorial(mid) > K: high = mid - 1 else: return 5 return 0

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:440. K-th Smallest in Lexicographical Order
下一篇:把我坑惨的一个update语句!
相关文章

 发表评论

暂时没有评论,来抢沙发吧~