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(1, k+2):

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



result = 0

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

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

        x = check[s][t]

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

            result += check[x][u]

result *= 6

result += k*(k+1)//2

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(1, k + 2):
        check[i][j] = gcd(i, j)
result = 0
for s in range(1, k + 1):
    for t in range(s, k + 1):
        x = check[s][t]
        for u in range(t + 1, k + 1):
            result += check[x][u]
result *= 6
result += k * (k + 1) // 2
print(result)

-    for j in range(i, k + 2): +    for j in range(1, k + 2): -    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] +    for t in range(s, k + 1): +        x = check[s][t] +        for u in range(t + 1, k + 1): +            result += check[x][u] +result *= 6 +result += k * (k + 1) // 2