import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

import math



i_i = lambda: int(i_s())

i_l = lambda: list(map(int, stdin.readline().split()))

i_s = lambda: stdin.readline().rstrip()



K = i_i()



res = sum([math.gcd(math.gcd(a, b), c) for a in range(1,K+1) for b in range(1,K+1) for c in range(1,K+1)])

print(res)
import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

import math



i_i = lambda: int(i_s())

i_l = lambda: list(map(int, stdin.readline().split()))

i_s = lambda: stdin.readline().rstrip()



K = i_i()



ans = 0

ab = []

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

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

        ab.append(math.gcd(a,b))

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

    for x in ab:

        ans += math.gcd(c,x)

print(ans)

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)
import math

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
K = i_i()
res = sum(
    [
        math.gcd(math.gcd(a, b), c)
        for a in range(1, K + 1)
        for b in range(1, K + 1)
        for c in range(1, K + 1)
    ]
)
print(res)

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)
import math

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
K = i_i()
ans = 0
ab = []
for a in range(1, K + 1):
    for b in range(1, K + 1):
        ab.append(math.gcd(a, b))
for c in range(1, K + 1):
    for x in ab:
        ans += math.gcd(c, x)
print(ans)

-res = sum( -    [ -        math.gcd(math.gcd(a, b), c) -        for a in range(1, K + 1) -        for b in range(1, K + 1) -        for c in range(1, K + 1) -    ] -) -print(res) +ans = 0 +ab = [] +for a in range(1, K + 1): +    for b in range(1, K + 1): +        ab.append(math.gcd(a, b)) +for c in range(1, K + 1): +    for x in ab: +        ans += math.gcd(c, x) +print(ans)