k = int(eval(input()))



"""

memo = [[-1 for i in range(k+1)] for j in range(k+1)]

def gcd(a, b):

    if b == 0:

        return a

    else:

        if memo[a][b] == -1:

            memo[a][b] = gcd(b, a % b)

        return memo[a][b]

"""



def my_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 = my_gcd(a, b)

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

            ans += my_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)

k = int(eval(input()))
"""
memo = [[-1 for i in range(k+1)] for j in range(k+1)]
def gcd(a, b):
    if b == 0:
        return a
    else:
        if memo[a][b] == -1:
            memo[a][b] = gcd(b, a % b)
        return memo[a][b]
"""


def my_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 = my_gcd(a, b)
        for c in range(1, k + 1):
            ans += my_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)

-""" -memo = [[-1 for i in range(k+1)] for j in range(k+1)] -def gcd(a, b): -    if b == 0: -        return a -    else: -        if memo[a][b] == -1: -            memo[a][b] = gcd(b, a % b) -        return memo[a][b] -""" -def my_gcd(a, b): +def gcd(a, b): -        t = my_gcd(a, b) +        t = gcd(a, b) +        if t == 1: +            ans += k +            continue -            ans += my_gcd(t, c) +            ans += gcd(t, c)