Skip to content

Instantly share code, notes, and snippets.

@junfenglx
Created September 1, 2015 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junfenglx/ac305184db62153b7734 to your computer and use it in GitHub Desktop.
Save junfenglx/ac305184db62153b7734 to your computer and use it in GitHub Desktop.
factorial trailing zeros test
# coding: utf-8
cache = dict()
def f(n):
if n <= 0:
return 0
prev = cache.get(n-1)
if not prev:
s = 1;
for i in range(1, n+1):
s *= i
cache[n] = s
else:
s = n * prev
return s
def trail0(n):
count = 0
while n:
r = n % 10
if r:
break
count += 1
n //= 10
return count
l = lambda x:trail0(f(x))
print(trail0(f(30)))
print(l(40))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment