import math

K = int(input())
total = 0

for i in range(1,K+1):
    for j in range(1, K+1):
        gcd1 = math.gcd(i, j)
        for k in range(1, K+1):
            total += math.gcd(gcd1, k)
print(total)