Kilonova - Sum of divisors
Authors: Mihnea Brebenel, Harshit Lohar
Explanation
For an integer , the sum of all divisors of the can be efficiently computed using the divisor function.
The formula states that if is the prime factorization of , then the divisors' sum is .
For this problem we need to compute sum of divisors of . If the prime factorization of is then the prime factorization of will be and we can compute the sum of divisors using the above formula, .
To compute the above sum we will have to find multiplicative inverse of modulo , for cases when is not relatively prime with we can notice that we wish to find the value of the following series modulo ,
for each , .
which is equal to , whenever,
We do need to compute the prime factors of , but thankfully this can be done in time.
Since, can be as large as , to avoid overflows we can use Euler's totient function and binary exponentiation to compute the powers modulo .
Implementation
Time Complexity:
C++
#include <fstream>using namespace std;#define ll long longconst int MOD = 1e9 + 7;Code Snippet: Modular Inverse and Binary Exponentiation functions (Click to expand)
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!