Factorial Trailing Zeros Problem

You are provided with a positive integer N. Your goal is to determine the smallest number whose factorial has at least N trailing zeros.

Example:

Input:
N = 1
Output:
5
Explanation:

The factorial of 5 (5!) is 120, which contains at least 1 trailing zero, making it the smallest such number.

Input:

The first line contains an integer 'T' indicating the number of test cases. Each test case consists of a single integer 'N' representing the required number of trailing zeros.

Output:

For each test case, output the smallest number whose factorial contains at least N trailing zeros. Each result should be on a new line.

Constraints:

  • 1 <= T <= 10
  • 0 <= N <= 108
  • Time Limit: 1 sec

Note:

You do not need to print anything. Just compute and return the result.
AnswerBot
4mo

Find the smallest number whose factorial has at least N trailing zeros.

  • Calculate the number of 5's in the prime factorization of the factorial to determine the trailing zeros.

  • Use binary search to find...read more

Help your peers!
Select
Add answer anonymously...

Salesforce Associate Software Engineer interview questions & answers

An Associate Software Engineer was asked Q. Largest BST Subtree Problem Given a binary tree with 'N' nodes, determine the si...read more
An Associate Software Engineer was asked Q. Reverse Linked List Problem Statement Given a singly linked list of integers, yo...read more
An Associate Software Engineer was asked Q. Implementing a Priority Queue Using Heap Ninja has been tasked with implementing...read more

Popular interview questions of Associate Software Engineer

An Associate Software Engineer was asked Q1. Largest BST Subtree Problem Given a binary tree with 'N' nodes, determine the si...read more
An Associate Software Engineer was asked Q2. Reverse Linked List Problem Statement Given a singly linked list of integers, yo...read more
An Associate Software Engineer was asked Q3. Implementing a Priority Queue Using Heap Ninja has been tasked with implementing...read more
Salesforce Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits