I am solving this problem in SPOJ which states that:
Let
To this I wrote the following code but it takes polynomial time. How can I optimise this code to run in sublinear time if its possible
m=18446744073709551616
def gcd(a,b):
if b==0:
retu a
else:
retu gcd(b,a%b)
for i in range(int(raw_input())):
n=int(raw_input())
s=0
for i in range(1,n+1):
for j in xrange(i+1,n+1):
s+=gcd(i,j)
print s%m



