给定一个整数n,请找出阶乘末尾有n个0的所有正整数:
我的解法:
def num_of_zero(N):
b = N
numZero = 0
while True:
if b > 0:
b = int(b / 5)
numZero += b
else:
break
return numZero
def solution(n):
alist = []
numZero = 0
res = 1
num = 1
while numZero <= n:
res *= num
num += 1
numZero = num_of_zero(num)
if numZero == n:
alist.append(num)
return alist
if __name__ == '__main__':
n = int(raw_input())
alist = solution(n)
print " ".join(str(i) for i in alist)
其中num_of_zero的函数是参照另一篇博客写的:https://blog.youkuaiyun.com/gogogo_sky/article/details/75734561