import math

k = int(eval(input()))

ans = 0

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

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

        x = math.gcd(a, b)

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

            y = math.gcd(x, c)

            if a == b and b == c:

                ans += y

            elif a == b or b == c:

                ans += y * 3

            else:

                ans += y * 6

print(ans)
import math

ans = 0

k = int(eval(input()))

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

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

        x = math.gcd(a, b)

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

            y = math.gcd(x, c)

            ans += y

print(ans)

import math

k = int(eval(input()))
ans = 0
for a in range(1, k + 1):
    for b in range(a, k + 1):
        x = math.gcd(a, b)
        for c in range(b, k + 1):
            y = math.gcd(x, c)
            if a == b and b == c:
                ans += y
            elif a == b or b == c:
                ans += y * 3
            else:
                ans += y * 6
print(ans)

import math

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

+ans = 0 -ans = 0 -    for b in range(a, k + 1): +    for b in range(1, k + 1): -        for c in range(b, k + 1): +        for c in range(1, k + 1): -            if a == b and b == c: -                ans += y -            elif a == b or b == c: -                ans += y * 3 -            else: -                ans += y * 6 +            ans += y