Given an integer n, the task is to find the number of trailing zeros in the function i.e. f(n) = 11 * 22 * 33 * … * nn.
Input: n = 5
f(5) = 11 * 22 * 33 * 44 * 55 = 1 * 4 * 27 * 256 * 3125 = 86400000
Input: n = 12
Approach: We know that 5 * 2 = 10 i.e. 1 trailing zero is the result of the multiplication of a single 5 and a single 2. So, if we have x number of 5 and y number of 2 then the number of trailing zeros will be min(x, y).
Now, for every number i in the series, we need to count the number of 2 and 5 in its factors say x and y but the number of 2s and 5s will be x * i and y * i respectively because in the series i is raised to the power itself i.e. ii. Count the number of 2s and 5s in the complete series and print the minimum of them which is the required answer.
Below is the implementation of the above approach:
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 number of trailing zeros in Binary representation of a number using Bitset
- Count number of trailing zeros in product of array
- Count unique numbers that can be generated from N by adding one and removing trailing zeros
- Smallest number divisible by n and has at-least k trailing zeros
- Find the smallest number X such that X! contains at least Y trailing zeros.
- Number of trailing zeros in N * (N - 2) * (N - 4)*....
- Count trailing zeroes in factorial of a number
- Count of Array elements greater than or equal to twice the Median of K trailing Array elements
- Count ways to split a Binary String into three substrings having equal count of zeros
- Smallest number with at least n trailing zeroes in factorial
- Trailing number of 0s in product of two factorials
- Largest number with maximum trailing nines which is less than N and greater than N-D
- Number of trailing zeroes in base B representation of N!
- Count numbers having N 0's and and M 1's with no leading zeros
- Count of N-bit binary numbers without leading zeros
- Check if the given array can be reduced to zeros with the given operation performed given number of times
- Check if any permutation of a number without any leading zeros is a power of 2 or not
- Remove leading zeros from a Number given as a string
- All possible numbers of N digits and base B without leading zeros
- Count of binary strings of length N having equal count of 0's and 1's and count of 1's ≥ count of 0's in each prefix substring
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.