Skip to content

Instantly share code, notes, and snippets.

@junfenglx
Created September 1, 2015 02:42
Show Gist options
  • Save junfenglx/ac305184db62153b7734 to your computer and use it in GitHub Desktop.
Save junfenglx/ac305184db62153b7734 to your computer and use it in GitHub Desktop.

Revisions

  1. junfeng_hu created this gist Sep 1, 2015.
    28 changes: 28 additions & 0 deletions test_trail0.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # 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))