how to sum the divisors of N mod K if all I have is N mod K?

785 Views Asked by At

The input to this problem is N.

I have to calculate 2 things:

1 - N! mod (10^9 + 7)

2 - sum of all divisors of N! mod (10^9 + 7)

I know how to do the first step, I'm wondering if there is a way to get the answer for the second part based in the result I got in the first one.

I've seen some posts about the sum of the divisors of a number throught its prime factorization but that would be too slow, I'm newbie with modular operations, so I'd appreciate any help (properties that could give me some idea on how to solve this).

1

There are 1 best solutions below

0
On
  1. Factor N! and store prime factors and their exponents in some data structure (Legendre's formula - http://www.cut-the-knot.org/blue/LegendresTheorem.shtml)
  2. Use equation (14) on this page: http://mathworld.wolfram.com/DivisorFunction.html (just loop over data structure)

Surely it can be done even without data structure, "on the fly".

Main idea is that you don't need to compute N! modulo at first. Factor N! and use its prime factors and exponents for simultaneous computation of N! modulo and sum of its divisors.

My explanation is kinda messy, but I hope you've got the idea. If you need it I can provide you a C function for this task.