Big Sum
Time limit2sMemory limit1024 MB
Given n up to 10^12, compute the sum over each divisor d of n of gcd(d, i) summed for i from 1 to n.
- Level
Medium6 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Problem
Kolya learned about divisibility and greatest common divisors in math class. The greatest common divisor of two positive integers a and b, written , is the largest positive integer g that divides both a and b.
His teacher gave him a homework problem: for a number k, compute . Kolya generalized it. For each divisor d of n, he sums gcd(d, i) for i up to n instead of up to d, giving . Here means that d is a divisor of n.
For large n, computing this expression directly takes a long time. Write a program that computes the value of this expression for a given n.
Input
The input file contains one positive integer n ().
Output
Print one number, the value of the expression for the given n.