# Factorial Trailing zeros - Python

I already solved this problem using C++ and python 2.7, I am beginner at python and trying to learn the solutions coded by others in python. I could understand many of the solutions written in python, except this one

import sys, zlib, base64

T=[int('0x'+z, base=16) for z in zlib.decompress(base64.b64decode(code)).split(',')]
raw_input()
t=[]
for n in [int(x) for x in sys.stdin.read().split()]:
t.append(str(n/5+n/25+n/125+n/625+n/3125+n/15625+T[n/78125]))
print '\n'.join(t)

```

why base64,zlib modules…?
what is the logic the user is trying to implement, the code is implemented by Candide

here is my guess.

the user needs to store certain integer values in the T array (i’ll try to explain them later).

regarding the constraints of the problem statement, N can be as large as 10^9.

the T array would be too long, and wouldn’t fit in the 50k-bytes source code constraint.

to achieve that, the user chooses :

• to write these integers in hexadecimal form
• to concatenate them with a comma separator
• to zip that string in order to compress it to fit in the source size constraint
• to use base64 encoding, because compressed stream can contain binary data (which needs \x for each)

then, considering the T array :

the Z(N) value is easily expressed with summing ratios between N and powers of 5,

because we all know trailing zeroes are from 2*5 powers (and powers of 2 are far more numerous than powers of 5).

it’s easy to see that 5=5^1, 25=5^2, 125=5^3, … i let you guess what is T then !

obviously :

def Z(N):
s = 0
for k in range(1, 13):
N /= 5
s += N
return s

def main():
T = int(raw_input())
for t in range(T):
N = int(raw_input())
print Z(N)

main()

is far easier to understand !

hope it helps.