Approach: The number of trailing zeros when f(N) is expressed in decimal notation is the number of times f(N) is divisible by 2 and the number of times f(N) is divisible by 5. There are two cases:
When N is odd then f(N) is the product of some odd numbers, so it does not break at 2. So the answer is always 0.
When N is even then f(N) can be represented as 2 (1 * 2 * 3 * …. * N/2). The number of times f(N) is divisible by 2 is greater than the number of times divisible by 5, so only consider the number of times divisible by 5. Now, this problem is similar to count trailing zeroes in factorial of a number.
Below is the implementation of the above approach:
Please Login to comment...