Understand this as counting number of times 5 appears, first count single 5, then 5*5, then 5*5*5, ..., for instance, if single 5 is already counted, 5*5 becomes single 5, ....., to count how many 5 will appear, we just need the value of n/i, and so on.

class Solution(object):

def trailingZeroes(self, n):

"""

:type n: int

:rtype: int

"""

i = 5

sum = 0

while n >= i:

sum += n / i

i *= 5

return sum