def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)

sum = 0
k = int(input())
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            sum = sum + gcd(gcd(i,j),k)

print(sum)