Project Euler 650 - Divisors of Binomial Product

Official link: https://projecteuler.net/problem=650

Thought Process

Recall the formula for sum of divisors function. It is based on the prime factorization of B(n), this mean that we don't actually need to calculate B(n) which grows too fast, instead we simply keep track of it's prime factorization.

We derive a relation for B(n) using B(n - 1) as follows:

Therefore, if we have the prime factorization of B(n - 1) we just need to add the prime factors of n^n and remove the factors of n!

In both of these cases we see that we need the prime factors of n, since 20,000 is quite small I just pre-compute all of them using a variation of the prime generation function.

Interactive Code

Enter a number (yourinput)

Code will output S(yourinput) (mod 1,000,000,007)