Created
September 1, 2015 02:42
-
-
Save junfenglx/ac305184db62153b7734 to your computer and use it in GitHub Desktop.
factorial trailing zeros test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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