K = int(eval(input()))



def gcd(a, b): # 最大公約数

    a = abs(a)

    b = abs(b)

    while b:

        a, b = b, a % b

    return a # int

ans = 0

for i in range(1,K+1):

    for j in range(i,K+1):

        for k in range(j,K+1):

            d = gcd(gcd(i,j),k)

            if i==j==k:

                ans += d

            elif i==j or j== k or k==i:

                ans += 3*d

            else:

                ans += 6*d

print(ans)



import math 

K = int(eval(input()))

ans = 0

for i in range(1,K+1):

    for j in range(i,K+1):

        for k in range(j,K+1):

            d = math.gcd(math.gcd(i,j),k)

            if i==j==k:

                ans += d

            elif i==j or j== k or k==i:

                ans += 3*d

            else:

                ans += 6*d

print(ans)

K = int(eval(input()))


def gcd(a, b):  # 最大公約数
    a = abs(a)
    b = abs(b)
    while b:
        a, b = b, a % b
    return a  # int


ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            d = gcd(gcd(i, j), k)
            if i == j == k:
                ans += d
            elif i == j or j == k or k == i:
                ans += 3 * d
            else:
                ans += 6 * d
print(ans)

import math

K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            d = math.gcd(math.gcd(i, j), k)
            if i == j == k:
                ans += d
            elif i == j or j == k or k == i:
                ans += 3 * d
            else:
                ans += 6 * d
print(ans)

+import math + - - -def gcd(a, b):  # 最大公約数 -    a = abs(a) -    b = abs(b) -    while b: -        a, b = b, a % b -    return a  # int - - -            d = gcd(gcd(i, j), k) +            d = math.gcd(math.gcd(i, j), k)