Search code examples
mathfactorial

Finding the Sum of divisors of a big factorial number?


I am trying to come up with an efficient way to list all divisors of a big factorial. Let's say 1000!. It is quite impossible with brute force. Is there an efficient approach? I need to process them i.e. to find their sum for a programming challenge.


Solution

    1. Find the prime factorisation of each number <= 1000. I would store this as a dictionary of prime -> power. E.g. for a single number like 24 {2: 3, 3: 1} because 24 is 2**3 * 3**1.
    2. Find the prime factorisation of 1000!. This is the combination of the dictionaries of numbers <= 1000 combined by summing all the values for each of the keys (the primes).
    3. You can then use equation 14 on this page as @AakashM already said.