import math



k = int(eval(input()))

ans = 0

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

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

        g = math.gcd(a,b)

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

            ans += math.gcd(g,c)

print(ans)     
import math

k = int(eval(input()))



map_list = [[0 for i in range(k+1)]for j in range(k+1)]

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

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

        map_list[i][j]=math.gcd(i,j)



ans=0

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

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

        gcd1 = map_list[i][j]

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

            ans+=map_list[k][gcd1]

print(ans)
import math

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

import math

k = int(eval(input()))
map_list = [[0 for i in range(k + 1)] for j in range(k + 1)]
for i in range(1, k + 1):
    for j in range(1, k + 1):
        map_list[i][j] = math.gcd(i, j)
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd1 = map_list[i][j]
        for k in range(1, k + 1):
            ans += map_list[k][gcd1]
print(ans)

+map_list = [[0 for i in range(k + 1)] for j in range(k + 1)] +for i in range(1, k + 1): +    for j in range(1, k + 1): +        map_list[i][j] = math.gcd(i, j) -for a in range(1, k + 1): -    for b in range(1, k + 1): -        g = math.gcd(a, b) -        for c in range(1, k + 1): -            ans += math.gcd(g, c) +for i in range(1, k + 1): +    for j in range(1, k + 1): +        gcd1 = map_list[i][j] +        for k in range(1, k + 1): +            ans += map_list[k][gcd1]