Given an integer n, we need to find the number of positive integers whose factorial ends with n zeros.
Input : n = 1 Output : 5 6 7 8 9 Explanation: Here, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880. Input : n = 2 Output : 10 11 12 13 14
Prerequisite : Trailing zeros in factorial.
Naive approach:We can just iterate through the range of integers and find the number of trailing zeros of all the numbers and print the numbers with n trailing zeros.
Efficient Approach:In this approach we use binary search. Use binary search for all the numbers in the range and get the first number with n trailing zeros. Find all the numbers with m trailing zeros after that number.
10 11 12 13 14
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count natural numbers whose factorials are divisible by x but not y
- Minimum number of Factorials whose sum is equal to N
- GCD of factorials of two numbers
- Sum of factorials of Prime numbers in a Linked list
- Calculating Factorials using Stirling Approximation
- Trailing number of 0s in product of two factorials
- Queries for the product of first N factorials
- Print factorials of a range in right aligned format
- Product of first N factorials
- Find the unit place digit of sum of N factorials
- Find last two digits of sum of N factorials
- Check if a given number divides the sum of the factorials of its digits
- Find sum of factorials in an array
- Count numbers having N 0's and and M 1's with no leading zeros
- Find the smallest number X such that X! contains at least Y trailing zeros.
- Count number of trailing zeros in Binary representation of a number using Bitset
- Number of trailing zeros in N * (N - 2) * (N - 4)*....
- Golang Program to Count Trailing Zeros in Factorial of a Number
- Find two numbers whose sum and GCD are given
- Count numbers < = N whose difference with the count of primes upto them is > = K
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : chitranayal