Mid/SeniorMath
Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.
A trailing zero is produced by a factor of 10, which comes from pairing factors of 2 and 5 in the factorial product. Your solution should run in O(log n) time.
Example 1
Input
n = 3Output
0Since 3! = 6, there are no trailing zeroes.
Example 2
Input
n = 5Output
1Since 5! = 120, there is exactly one trailing zero.
Constraints
- 0 <= n <= 10^4