import math

k = int(eval(input()))

ans = 0

list_gcd = [[0]*202 for _ in range(202)]



for i in range(1, 201):

    for j in range(i, 201):

        num = math.gcd(i, j)

        list_gcd[i][j] = num

        list_gcd[j][i] = num



ans = 0

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

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

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

            num = list_gcd[i][j]

            ans += list_gcd[num][l]



print(ans)
import math

k = int(eval(input()))

ans = 0

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

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

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

            num = math.gcd(i, j)

            ans += math.gcd(num,l)



print(ans)
import math

k = int(eval(input()))
ans = 0
list_gcd = [[0] * 202 for _ in range(202)]
for i in range(1, 201):
    for j in range(i, 201):
        num = math.gcd(i, j)
        list_gcd[i][j] = num
        list_gcd[j][i] = num
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            num = list_gcd[i][j]
            ans += list_gcd[num][l]
print(ans)

import math

k = int(eval(input()))
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            num = math.gcd(i, j)
            ans += math.gcd(num, l)
print(ans)

-list_gcd = [[0] * 202 for _ in range(202)] -for i in range(1, 201): -    for j in range(i, 201): -        num = math.gcd(i, j) -        list_gcd[i][j] = num -        list_gcd[j][i] = num -ans = 0 -            num = list_gcd[i][j] -            ans += list_gcd[num][l] +            num = math.gcd(i, j) +            ans += math.gcd(num, l)