



import math

rst = 0

K = int(eval(input()))

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

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

        tmp = math.gcd(i, j)

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

            rst += math.gcd(k, tmp)

print(rst)





from math import gcd as g





k = int(eval(input()))

ans = 0

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

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

        temp = g(a, b)

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

            ans += g(temp, c)





print(ans)

import math

rst = 0
K = int(eval(input()))
for i in range(1, K + 1):
    for j in range(1, K + 1):
        tmp = math.gcd(i, j)
        for k in range(1, K + 1):
            rst += math.gcd(k, tmp)
print(rst)

from math import gcd as g

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

-import math +from math import gcd as g -rst = 0 -K = int(eval(input())) -for i in range(1, K + 1): -    for j in range(1, K + 1): -        tmp = math.gcd(i, j) -        for k in range(1, K + 1): -            rst += math.gcd(k, tmp) -print(rst) +k = int(eval(input())) +ans = 0 +for a in range(1, k + 1): +    for b in range(1, k + 1): +        temp = g(a, b) +        for c in range(1, k + 1): +            ans += g(temp, c) +print(ans)