from fractions import gcd

K = int(input())
total = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            tmp = gcd(a, b)
            total += gcd(tmp, c)

print(total)
