from math import gcd

k = int(eval(input()))

s = 0

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

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

        t = gcd(x, y)

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

            s += gcd(t, z)

print(s)
from math import gcd

k = int(eval(input()))

s = 0

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

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

        t = gcd(x, y)

        if t == 1:

            s += k

            continue

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

            s += gcd(t, z)

print(s)
from math import gcd

k = int(eval(input()))
s = 0
for x in range(1, k + 1):
    for y in range(1, k + 1):
        t = gcd(x, y)
        for z in range(1, k + 1):
            s += gcd(t, z)
print(s)

from math import gcd

k = int(eval(input()))
s = 0
for x in range(1, k + 1):
    for y in range(1, k + 1):
        t = gcd(x, y)
        if t == 1:
            s += k
            continue
        for z in range(1, k + 1):
            s += gcd(t, z)
print(s)

+        if t == 1: +            s += k +            continue