k = int(eval(input()))



def gcd(a, b):

    if a < b: a, b = b, a

    c = a % b

    if c == 0: return b

    while c!=0:

        c = a % b

        a, b = b, c

    return a



ans = 0

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

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

        t = gcd(a, b)

        if t == 1:

            ans += k

            continue

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

            ans += gcd(t, c)

print(ans)

from math import gcd

k = int(eval(input()))

ans = 0

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

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

        t = gcd(a, b)

        if t == 1:

            ans += k

            continue

        for c in range(1, k+1): ans += gcd(t, c)

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


def gcd(a, b):
    if a < b:
        a, b = b, a
    c = a % b
    if c == 0:
        return b
    while c != 0:
        c = a % b
        a, b = b, c
    return a


ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        t = gcd(a, b)
        if t == 1:
            ans += k
            continue
        for c in range(1, k + 1):
            ans += gcd(t, c)
print(ans)

from math import gcd

k = int(eval(input()))
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        t = gcd(a, b)
        if t == 1:
            ans += k
            continue
        for c in range(1, k + 1):
            ans += gcd(t, c)
print(ans)

+from math import gcd + - - -def gcd(a, b): -    if a < b: -        a, b = b, a -    c = a % b -    if c == 0: -        return b -    while c != 0: -        c = a % b -        a, b = b, c -    return a - -