FunctionRacerProblemsRace

Smallest Factorial With K Zeros

HardMathPython, JavaScript, TypeScript, Java, C++

The number n! (n factorial) is 1 * 2 * ... * n. Return the smallest n for which n! ends in exactly k zeros, or -1 if no factorial ends in exactly k zeros.

Example 1

k 3
returns 15

15! is the first factorial with three factors of 5 (from 5, 10 and 15), and each one makes a zero.

Example 2

k 5
returns -1

24! ends in four zeros and 25! ends in six, because 25 brings two factors of 5 at once.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems