K = int(eval(input()))

 

from itertools import product

kumi = product(list(range(1, K+1)), repeat=3)

 

from math import gcd

 

memo = [[None for i in range(K+1)] for i in range(K+1)]

# memo2 = {}

 

ans = 0

for a, b, c in kumi:

    a, b, c = sorted([a, b, c])

    if memo[a][b] is not None:

        v = memo[a][b]

    else:

        v = gcd(a, b)

        memo[a][b] = v

        memo[b][a] = v

    d = gcd(v, c)

    ans += d

 

print(ans)
K = int(eval(input())) 

from math import gcd

ans = 0

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

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

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

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

print(ans)
K = int(eval(input()))
from itertools import product

kumi = product(list(range(1, K + 1)), repeat=3)
from math import gcd

memo = [[None for i in range(K + 1)] for i in range(K + 1)]
# memo2 = {}
ans = 0
for a, b, c in kumi:
    a, b, c = sorted([a, b, c])
    if memo[a][b] is not None:
        v = memo[a][b]
    else:
        v = gcd(a, b)
        memo[a][b] = v
        memo[b][a] = v
    d = gcd(v, c)
    ans += d
print(ans)

K = int(eval(input()))
from math import gcd

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            ans += gcd(gcd(i, j), k)
print(ans)

-from itertools import product - -kumi = product(list(range(1, K + 1)), repeat=3) -memo = [[None for i in range(K + 1)] for i in range(K + 1)] -# memo2 = {} -for a, b, c in kumi: -    a, b, c = sorted([a, b, c]) -    if memo[a][b] is not None: -        v = memo[a][b] -    else: -        v = gcd(a, b) -        memo[a][b] = v -        memo[b][a] = v -    d = gcd(v, c) -    ans += d +for i in range(1, K + 1): +    for j in range(1, K + 1): +        for k in range(1, K + 1): +            ans += gcd(gcd(i, j), k)