All problems

Problem 235

Sum of Divisors

Easy · 10 pts · Math, Number Theory

Problem

You are given a positive integer N. Print the sum of all its positive divisors, including 1 and N itself. Divisors come in pairs d and N / d, so only d up to the square root of N needs checking: add both numbers of each pair, and add the square root only once when N is a perfect square. For N up to 10^12, that is at most 10^6 checks. The sum can exceed the 32-bit range.

Input

A single integer N.

Output

Print the sum of divisors.

Constraints

1 <= N <= 1000000000000

Example input

12

Example output

28

Explanation

The divisors of 12 are 1, 2, 3, 4, 6 and 12, which pair up as (1, 12), (2, 6) and (3, 4). Their sum is 1 + 2 + 3 + 4 + 6 + 12 = 28.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Fibonacci Modulo for Huge N Next: Euler's Totient Function