Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def lznd_trailing_zeros (n):
- "Return the number of trailing zeros of N!"
- r = 0
- for i in range(5, n+1, 5):
- while i%5 == 0:
- r += 1
- i = i / 5
- return r
- def lznd_fact (n):
- "Return the last non-zero digit of N!"
- f2 = f5 = lznd_trailing_zeros(n)
- r = 1
- for i in range(1,n+1):
- while f2 > 0 and i%2 == 0:
- f2 -= 1
- i /= 2
- while f5 > 0 and i%5 == 0:
- f5 -= 1
- i /= 5
- r = (i*r) % 10
- return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement