![]() |
VOOZH | about |
Given a number n, count the total number of divisors of n!.
Examples:
Input : n = 4
Output: 8
Explanation:
4! is 24. Divisors of 24 are 1, 2, 3, 4, 6,
8, 12 and 24.Input : n = 5
Output : 16
Explanation:
5! is 120. Divisors of 120 are 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24 30, 40, 60 and 12
A Simple Solution is to first compute the factorial of the given number, then count the number of divisors of the factorial. This solution is not efficient and may cause overflow due to factorial computation.
A better solution is based on Legendre’s formula. Below are the step:
Below is the implementation of the above idea.
30
Time Complexity: (O(n * log(logn))
Auxiliary Space: O(n)
This article is reviewed by team GeeksforGeeks.