Trailing Zeros in Factorial Problem

Find the number of trailing zeroes in the factorial of a given number N.

Input:

The first line contains an integer T representing the number of test cases.
Each of the following T lines contains an integer N, for which trailing zeros in N! need to be found.

Output:

For each test case, output a single integer that represents the number of trailing zeros in N!.

Example:

Input:
2
5
10

Output:

1
2

Explanation:

For N=5, the factorial 5! is 120, which has 1 trailing zero.
For N=10, the factorial 10! is 3628800, which has 2 trailing zeros.

Constraints:

  • 1 <= T <= 10^4
  • 1 <= N <= 10^9

Note: You are not required to print anything; the system handles the output. Implement the necessary function to achieve the desired result.

AnswerBot
4mo

Count the number of trailing zeros in the factorial of a given number.

  • To find the number of trailing zeros in N!, count the number of factors of 5 in the prime factorization of N.

  • Each factor of 5 cont...read more

Help your peers!
Select
Add answer anonymously...

Nagarro Associate Engineer interview questions & answers

An Associate Engineer was asked 9mo agoQ. Write a program.
An Associate Engineer was asked 10mo agoQ. How do you find the largest element in an array with O(N) complexity?
An Associate Engineer was asked 10mo agoQ. How do you detect a loop in a linked list?

Popular interview questions of Associate Engineer

An Associate Engineer was asked 9mo agoQ1. Write a program.
An Associate Engineer was asked 10mo agoQ2. How do you find the largest element in an array with O(N) complexity?
An Associate Engineer was asked 10mo agoQ3. How do you detect a loop in a linked list?
Nagarro Associate 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