![]() |
VOOZH | about |
Given a number n, we need to calculate the sum of divisors of factorial of the number.
Examples:
Input : 4 Output : 60 Factorial of 4 is 24. Divisors of 24 are 1 2 3 4 6 8 12 24, sum of these is 60. Input : 6 Output : 2418
A Simple Solution is to first compute the factorial of the given number, then count the number divisors of the factorial. This solution is not efficient and may cause overflow due to factorial computation.
Below is the implementation of the above approach:
Output :
60
Time Complexity: O(n!)
Auxiliary Space: O(1)
An efficient solution is based on Legendre’s formula. Below are the steps.
Output:
60
Time Complexity: O(n*log(log(n)))
Auxiliary Space: O(n)