import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

k = int(input())

L = []
for i in range(1, k+1):
    for j in range(1, k+1):
        for p in range(1, k+1):
            L.append(gcd(i, j, p))

print(sum(L))
