Sphere Online Judge

SPOJ Problem Set (classical)

3871. GCD Extreme

Problem code: GCDEX

Given the value of N, you will have to find the value of G. The meaning of G is given in the following code

G=0;

for(k=i;k< N;k++)

for(j=i+1;j<=N;j++)

{

G+=gcd(k,j);

}

/*Here gcd() is a function that finds the greatest common divisor of the two input numbers*/

Input

The input file contains at most 20000 lines of inputs. Each line contains an integer N (1Output

For each line of input produce one line of output. This line contains the value of G for the corresponding N. The value of G will fit in a 64-bit signed integer.

Example

Input:
10
100
200000
0

Output:
67
13015
143295493160

Time limit has been changed. Some AC solutions get TLE

Added by:Phenomenal
Date:2009-02-16
Time limit:3s
Source limit:50000B
Languages:All except: ERL TECS JS
Resource:ACM World Final Warm up 1 - 2008

hide comments
2009-09-11 11:26:11 Pa1
O(n^(3/2)) wont work ??

Yeah it doesnt, we need a Pure sieve's implementation for getting phi values.

very easy optimizations to my logic has got AC :)

Last edit: 2009-09-11 13:43:41
2009-06-14 17:22:13 .::: Pratik :::.
got ACC on UVA in 0.032s but TLE here :(

Last edit: 2009-06-14 17:22:30
2009-03-12 18:52:13 zhengxi
correct task: http://icpcres.ecs.baylor.edu/onlinejudge/external/114/11424.html
the only difference is bigger maximal N (about 1000000 instead of 200000 there)

Last edit: 2009-03-12 18:52:13
2009-03-07 16:00:10 [Trichromatic] XilinX
The problem setter has been banned for his cheating actions. To see the original description, you may go to UVa Online Judge(http://icpcres.ecs.baylor.edu) and find that problem(id:11426).
SPOJ System © 2008-2010 Sphere Research Labs. All Rights Reserved.