172. Factorial Trailing Zeroes

http://www.purplemath.com/modules/factzero.htm
2比5多,所以以5的数量来确定有多少10,但是5也有可能一个数字包含多个5

class Solution(object):
    def trailingZeroes(self, n):
        """
        :type n: int
        :rtype: int
        """
        count = 0
        div = 5
        while True:
            if n / div < 1:
                break
            count += n / div
            div *= 5
        return count

你可能感兴趣的:(172. Factorial Trailing Zeroes)