bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 793. Preimage Size of Factorial Zeroes Function

793. Preimage Size of Factorial Zeroes Function

Leetcode Solutions

Binary Search to Find the Number of Integers with k Trailing Zeroes in Factorial

  1. Define a function zeta(x) that calculates the number of trailing zeroes in x! by summing the integer division of x by increasing powers of 5.
  2. Define a binary search function to find the smallest x such that zeta(x) >= k.
  3. Define a binary search function to find the largest x such that zeta(x) <= k.
  4. If the smallest x is greater than the largest x, return 0 as there are no integers with exactly k trailing zeroes.
  5. Otherwise, return 5 as there are exactly 5 integers with k trailing zeroes.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...