k = int(input())

def gcd(a, b):
    while True:
        r = a % b
        a, b = b, r
        if b == 0:
            return a
    
def gcds(a, b, c):
    d = gcd(a, b)
    return gcd(c, d)

ans = 0
for i in range(1, k+1):
    for j in range(i, k+1):
        for l in range(j, k+1):
            if (i == j) and (j == l):
                ans += gcds(i, j, l)
            elif (i != j) and(j != l) and (l != i):
                ans += 6*gcds(i, j, l)
            else:
                ans += 3*gcds(i, j, l)
print(ans)