Factorial Trailing Zeroes
Real-world version: Zeros At The End Of The Run FigureThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def trailing_zeroes(n: int) -> int:public int trailingZeroes(int n)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's