#K35717. Sum of Proper Divisors

    ID: 25594 Type: Default 1000ms 256MiB

Sum of Proper Divisors

Sum of Proper Divisors

Given an integer \( n \), compute the sum of all its proper divisors. A proper divisor is any divisor of \( n \) that is strictly less than \( n \). For example, since the proper divisors of 6 are 1, 2, and 3, their sum is 6.

Note that for \( n \le 1 \), the sum of proper divisors is defined to be 0.

Your task is to read a single integer from standard input, calculate the sum of its proper divisors using the most efficient method possible, and write the result to standard output.

The formula for the sum is computed as follows:

[ S(n) = \begin{cases} 0, & n \leq 1 \ 1 + \sum_{i=2}^{\sqrt{n}} \Bigl( i ;\text{if }i^2=n \text{, else } (i + \frac{n}{i}) \Bigr), & n > 1 \end{cases} ]

inputFormat

The input consists of a single integer \( n \) (\(1 \leq n \leq 10^9\)).

outputFormat

Output a single integer representing the sum of all proper divisors of \( n \).

## sample
6
6