from math import gcd
k=int(input())
ans=sum(range(1,k+1))
for a in range(1,k):
    for b in range(a+1,k+1):
        ans+=6*gcd(a,b)
for a in range(1,k-1):
    for b in range(a+1,k):
        for c in range(b+1,k+1):
            ans+=6*gcd(a,gcd(b,c))
print(ans)