设计一个算法,计算出n阶乘中尾部零的个数

理论分析和C参考代码:http://blog.chinaunix.net/uid-20766194-id-1850404.html点击打开链接

Python 代码:

class Solution:
    """
    @param: n: An integer
    @return: An integer, denote the number of trailing zeros in n!
    """
    def trailingZeros(self, n):
        # write your code here, try to do it without arithmetic operators.
        num = 0
        for i in range(5,n+1,5):
            j = i
            while (j%5==0):
                num += 1
                j = j/5
        return (num)

你可能感兴趣的:(Python)