import math

K = int(eval(input()))



# table = np.zeros((K,K), dtype="int16")

table = [[0] * K for i in range(K)]



for a in range(K):

    for b in range(a, K):

        tmp = math.gcd(a+1, b+1)

        table[a][b] = tmp

        table[b][a] = tmp



res = 0

for a in range(K):

    for b in range(K):

        for c in range(K):

            res += table[table[a][b]-1][c]

print(res)     
import math

K = int(eval(input()))



res = 0

for a in range(K):

    for b in range(K):

        for c in range(K):

            res += math.gcd(math.gcd(a+1, b+1), c+1)

print(res)   
import math

K = int(eval(input()))
# table = np.zeros((K,K), dtype="int16")
table = [[0] * K for i in range(K)]
for a in range(K):
    for b in range(a, K):
        tmp = math.gcd(a + 1, b + 1)
        table[a][b] = tmp
        table[b][a] = tmp
res = 0
for a in range(K):
    for b in range(K):
        for c in range(K):
            res += table[table[a][b] - 1][c]
print(res)

import math

K = int(eval(input()))
res = 0
for a in range(K):
    for b in range(K):
        for c in range(K):
            res += math.gcd(math.gcd(a + 1, b + 1), c + 1)
print(res)

-# table = np.zeros((K,K), dtype="int16") -table = [[0] * K for i in range(K)] -for a in range(K): -    for b in range(a, K): -        tmp = math.gcd(a + 1, b + 1) -        table[a][b] = tmp -        table[b][a] = tmp -            res += table[table[a][b] - 1][c] +            res += math.gcd(math.gcd(a + 1, b + 1), c + 1)