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


n = int(input())
ans = 0
if n > 2:
    for i in range(1, n-1):
        for j in range(i + 1, n):
            for k in range(j + 1, n + 1):
                tmp = gcd(i, j)
                ans += gcd(tmp, k) * 6
if n > 1:
    for i in range(1, n):
        for j in range(i + 1, n + 1):
            ans += gcd(i, j) * 6
ans += n*(1+n)//2
print(ans)
