def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

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

N = getInput()[0]
sums = 0
for i in range(1, N+1):
    for j in range(1, N+1):
        if i == j:
            n = i
        else:
            n = gcd(max(i, j), min(i,j))

        for k in range(1, N+1):
            if n == k:
                sums += n
            elif n == 1 or k == 1:
                sums += 1
            else:
                sums += gcd(max(n, k), min(n, k))

print(sums)
