All problems
0637MediumMath

Zeros At The End Of The Run Figure

Tracked in this browser only
Write code

Trains the technique from

LeetCode 172Factorial Trailing Zeroes

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

At the close of a production run the log posts one figure: the shift numbers 1, 2, up to n all multiplied together. A run of no shifts posts the figure 1.

Write the posted figure in decimal. Return how many zeros stand to the right of its last non-zero digit. Aim for a running time that grows only with the logarithm of n, since for n near the upper bound the figure itself runs to tens of thousands of digits.

Examples

Example 1

Input
n = 24
Output
4

The figure posted for 24 shifts is 620448401733239439360000, which ends in four zeros before its last non-zero digit 6.

Example 2

Input
n = 124
Output
28

The figure for 124 shifts is a 208-digit number ending with 28 zeros, so 28 is returned.

Example 3

Input
n = 1249
Output
308

The figure for 1249 shifts ends with 308 zeros.

Constraints

  • 0 <= n <= 10^4

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def trailing_zeroes(n: int) -> int:
Java
public int trailingZeroes(int n)
September 7
Apply