Sum of divisors

Write codeMedium20 min

Your task

Compute sigma(n), the sum of all positive divisors of n (including 1 and n itself), for a single positive integer n up to about 10^12. A loop to n is far too slow; instead factorize n by trial division up to sqrt(n) and use the multiplicative product formula for sigma over prime powers. Return 0 for n <= 0.

Examples

sum_of_divisors(n: int) -> int
Example 1
Inputsum_of_divisors(12)
Output28