Given an integer n, return the number of trailing zeroes in n!.

Example 1:


Input: 3
Output: 0
Explanation: 3! = 6, no trailing zero.

Example 2:


Input: 5
Output: 1
Explanation: 5! = 120, one trailing zero.

Note: Your solution should be in logarithmic time complexity.

Source: leetcode | Difficulty: EASY
Tags: Mathematics

Starter code: class Solution:
    def trailingZeroes(self, n: int) -> int:
        

Solutions:
class Solution:

	def trailingZeroes(self, n):
		n_fives = 0
		while n > 0:
			n = n // 5
			n_fives += n
		return n_fives


class Solution:

	def trailingZeroes(self, n):
		c = 0
		while n > 0:
			n //= 5
			c += n
		return c


class Solution:

	def trailingZeroes(self, n):
		count = 1
		a = 5
		ans = 0
		while a <= n:
			ans += n // a
			count += 1
			a = 5 ** count
		return ans


class Solution:

	def trailingZeroes(self, n):
		return 0 if n == 0 else n // 5 + self.trailingZeroes(n // 5)


class Solution:

	def trailingZeroes(self, n):
		count = 0
		while n:
			count = count + n // 5
			n = n // 5
		return count


class Solution:

	def trailingZeroes(self, n):
		two = 0
		five = 0
		tmp = n
		while tmp != 0:
			tmp = tmp // 5
			five = five + tmp
		tmp = n
		while tmp != 0:
			tmp = tmp // 2
			two = two + tmp
		res = min(five, two)
		return res


class Solution:

	def trailingZeroes(self, n):
		ans = 0
		i = 5
		while n // i:
			ans += n // i
			i *= 5
		return ans


class Solution:

	def trailingZeroes(self, n):
		return sum([n // 5 ** i for i in range(1, 20)])


class Solution:

	def trailingZeroes(self, n):
		res = 5
		ans = 0
		while res < n + 1:
			ans += int(n / res)
			res = 5 * res
		return ans


class Solution:

	def trailingZeroes(self, n):
		trz = 0
		div = 5
		while div <= n:
			trz += int(n / div)
			div *= 5
		return trz


class Solution:

	def trailingZeroes(self, n):
		if n < 5:
			return 0
		elif n < 10:
			return 1
		i = 0
		while 5 ** (i + 1) <= n:
			i += 1
		s = n // 5
		j = 2
		while j <= i:
			s += n // 5 ** j
			j += 1
		return int(s)


class Solution:

	def trailingZeroes(self, n):
		num2 = 0
		div = 2
		quot = n // div
		while quot:
			num2 += quot
			div *= 2
			quot = n // div
		num5 = 0
		div = 5
		quot = n // div
		while quot:
			num5 += quot
			div *= 5
			quot = n // div
		return min(num2, num5)