Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Smallest factorial number

Medium Acceptance 38.79% Points 30.00

Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes.

Examples
Example 1

Example 1

Input: n = 1

Output: 5

Explanation: 5! = 120 which has at least 1 trailing 0.

Example 2

Example 2

Input: n = 6

Output: 25

Explanation: 25! has at least 6 trailing 0.

Hints
Hint 1
Expected Time Complexity: O(log2 N * log5 N).
Hint 2
Expected Auxiliary Space: O(1).
Constraints
  • 1 <= n <= 10^4
Companies
Apple Visa Walmart
Topics
Searching Algorithms
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions