Problem statement

https://binarysearch.com/problems/Factory-Trail/

Solution

Equal to Leetcode 0172 Factorial Trailing Zeroes.

Complexity

It is O(log n) for time and O(1) for space.

Code

class Solution:
    def solve(self, n):
        q, ans = 5, 0
        while q <= n:
            ans += n//q
            q *= 5
            
        return ans