from math import gcd



n = int(eval(input()))

ans = 0

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

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

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

            ans += gcd(gcd(i, j), k)

print(ans)

from math import gcd



n = int(eval(input()))

ans = 0

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

    for j in range(i, n + 1):

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

            if i == j == k:

                ans += gcd(gcd(i, j), k)

            elif i == j or i == k or j == k:

                ans += gcd(gcd(i, j), k) * 3

            else:

                ans += gcd(gcd(i, j), k) * 6

print(ans)

from math import gcd

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

from math import gcd

n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
    for j in range(i, n + 1):
        for k in range(j, n + 1):
            if i == j == k:
                ans += gcd(gcd(i, j), k)
            elif i == j or i == k or j == k:
                ans += gcd(gcd(i, j), k) * 3
            else:
                ans += gcd(gcd(i, j), k) * 6
print(ans)

-    for j in range(1, n + 1): -        for k in range(1, n + 1): -            ans += gcd(gcd(i, j), k) +    for j in range(i, n + 1): +        for k in range(j, n + 1): +            if i == j == k: +                ans += gcd(gcd(i, j), k) +            elif i == j or i == k or j == k: +                ans += gcd(gcd(i, j), k) * 3 +            else: +                ans += gcd(gcd(i, j), k) * 6