Trailing zeros in factorial

You are given an integer N, you need to find the number of trailing zeroes in N! (N factorial).

Note:

1. Trailing zeros in a number can be defined as the number of continuous suffix zeros starting from the zeroth place of a number.
2. For example, if a number X = 1009000, then the number of trailing zeros = 3 where the zeroth place is 0, the tenth place is 0, the hundredth place is 0.
3. ! means “FACTORIAL”. Factorial of a number is calculated by the product of the integer and all integers below it till 1.
4. Value of 0! is 1.
Input Format:
The first line of the input contains an integer T denoting the number of test cases.

The first and the only line of each test case contains an integer N, denoting the number whose number of trailing zeros from N! is to be found.
Output Format:
The only line of output of each test case should contain an integer, denoting the number of trailing zeroes in N!
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10^4
1 <= N <= 10^9

Time Limit: 1sec
CodingNinjas
author
2y

Step-1: Firstly, take a variable trailing_zero = 0. then take var num = 5
Step-2: trailing_zero += divide the number given(n) by num then
Step-3: We will make the square of 5 i.e num = num *num, then cu...read more

CodingNinjas
author
2y
Find the factorial of the number
  • Calculate the factorial of N.
  • Initialise FACT = 1 to store factorial of N, iterate 1 <= i <= N and do FACT = FACT * i.
  • Count the number of trailing zeroes in FACT. Initia...read more
CodingNinjas
author
2y
Prime Factors
  • We know that trailing zero in any number comes if, 10 is a divisor of the number.
  • 10 itself comes from 2*5.
  • So, we need to keep count of all products of 5 and 2, like 2*5 = 10, 4*5 = 20, et...read more
Add answer anonymously...
Capgemini Software Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter