N阶乘末尾有几个0

N阶乘末尾有几个0

若阶乘最后为0,则必须有2*5,相当于把每个阶乘因子分解并计算2和5的个数

现实中2的个数肯定大于5,所以只需要计算5的个数

代码实现

def zero_count(n):
    count = 0
    while n > 0:
        n //= 5
        count += n
    return count


print(zero_count(26))