题目:
Given an integer n, return the number of trailing zeroes in n!.
题意:
给定一个整数n,求出n!中最末尾包含的0的个数
代码:
class Solution(object):
def trailingZeroes(self, n):
"""
:type n: int
:rtype: int
"""
if n <= 0 :
return 0
else :
count = 0
while n/5 != 0 :
n = n/5
count = count + n
return count
笔记:
2*5就会产生一个0,然而2的个数始终比5多,故只用计算n!中5的个数,5的个数即为n!中末尾为0的个数
n/5 就会得到n中5的个数,但是除了计算n/5,还要计算n/5/5,n/5/5/5,……直到商为0
参考:http://blog.csdn.net/feliciafay/article/details/42336835