LCMSUM - LCM Sum
Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes the Least Common Multiple of the integers i and n.
The first line contains T the number of test cases. Each of the next T lines contain an integer n.
Output T lines, one for each test case, containing the required sum.
Sample Input: 3 1 2 5 Sample Output: 1 4 55
1 <= T <= 300000
1 <= n <= 1000000
interesting problem.Had to refer the web to get the first idea.Last edit: 2014-11-03 13:05:20
learnt something new..:)Last edit: 2014-02-16 19:21:14
adhikari vushesh babu:
At last green light :)
Great Problem! Learnt a lot about totient function... But I think there's some server instability, my earlier solution ran in 4.19s on ideone & here it TLE'd, my improved solution ran in 0.42s on ideone & here it took 4.13s. Strange. :)
One does not simply calculate LCM :D
finally got AC....:)
One does not simply uses Java in Spoj <Boromir> :D
Not enough time or too many test cases for Java. Precompute sum for all n from 1 to 1000000 and store results in array. Elapsed time for this effort is 0.250 sec.