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
- GCD of factorials of two numbers
- Count natural numbers whose factorials are divisible by x but not y
- Count numbers having N 0's and and M 1's with no leading zeros
- Product of first N factorials
- Find sum of factorials in an array
- Queries for the product of first N factorials
- Find last two digits of sum of N factorials
- Calculating Factorials using Stirling Approximation
- Trailing number of 0s in product of two factorials
- Check if a given number divides the sum of the factorials of its digits
- Print factorials of a range in right aligned format
- Find the unit place digit of sum of N factorials
- 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
- Permutation of numbers such that sum of two consecutive numbers is a perfect square
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