from fractions import gcd

k = int(eval(input()))

check = [[1 for _ in range(k+3)] for i in range(k+3)]

for i in range(1, k+2):

    for j in range(i, k+2):

        check[i][j] = gcd(i, j)



result = 0

for s in range(1, k+1):

    for t in range(1, k+1):

        for u in range(1, k+1): 

            n, m = sorted([s, t])

            x = check[n][m]

            x, y = sorted([x, u])

            result += check[x][y]

print(result)
from fractions import gcd

k = int(eval(input()))

check = [[1 for _ in range(k+3)] for i in range(k+3)]

for i in range(1, k+2):

    for j in range(i, k+2):

        check[i][j] = gcd(i, j)



result = 0

for s in range(1, k+1):

    for t in range(1, k+1):

        n, m = sorted([s, t])

        x = check[n][m]

        for u in range(1, k+1): 

            y, z = sorted([x, u])

            result += check[y][z]

print(result)
from fractions import gcd

k = int(eval(input()))
check = [[1 for _ in range(k + 3)] for i in range(k + 3)]
for i in range(1, k + 2):
    for j in range(i, k + 2):
        check[i][j] = gcd(i, j)
result = 0
for s in range(1, k + 1):
    for t in range(1, k + 1):
        for u in range(1, k + 1):
            n, m = sorted([s, t])
            x = check[n][m]
            x, y = sorted([x, u])
            result += check[x][y]
print(result)

from fractions import gcd

k = int(eval(input()))
check = [[1 for _ in range(k + 3)] for i in range(k + 3)]
for i in range(1, k + 2):
    for j in range(i, k + 2):
        check[i][j] = gcd(i, j)
result = 0
for s in range(1, k + 1):
    for t in range(1, k + 1):
        n, m = sorted([s, t])
        x = check[n][m]
        for u in range(1, k + 1):
            y, z = sorted([x, u])
            result += check[y][z]
print(result)

+        n, m = sorted([s, t]) +        x = check[n][m] -            n, m = sorted([s, t]) -            x = check[n][m] -            x, y = sorted([x, u]) -            result += check[x][y] +            y, z = sorted([x, u]) +            result += check[y][z]