Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/sonlar-ekublar-yigindisi

Sum of GCDs

Hard 1000 ms 128 MB 95%
Share

You are given a positive integer $n$. Find the sum $\gcd(1, n) + \gcd(2, n) + \ldots + \gcd(n, n)$, where $\gcd(x, y)$ is the greatest common divisor (GCD) of $x$ and $y$. For example, for $n = 6$ it is $1 + 2 + 3 + 2 + 1 + 6 = 15$.

The numbers from 1 to n, under each its GCD with n, and their sum

Input

One positive integer $n$.

Output

One integer — the sum.

Note

$1 \le n \le 10^{12}$

Examples

Input #1
6
Output #1
15
Input #2
1
Output #2
1

Sign in to submit a solution

Signing up is free and takes a minute.