# ABC162C



from fractions import gcd

from math import gcd



k = int(eval(input()))

total = 0

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

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

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

            # print(a, b, c, gcd(a, gcd(b, c)))

            total += gcd(a, gcd(b, c))

print(total)

from math import gcd



k = int(eval(input()))

total = 0

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

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

        t = gcd(a, b)

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

            # print(a, b, c, gcd(a, gcd(b, c)))

            total += gcd(t, c)

print(total) # sample_02 1982 ms

# ABC162C
from fractions import gcd
from math import gcd

k = int(eval(input()))
total = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            # print(a, b, c, gcd(a, gcd(b, c)))
            total += gcd(a, gcd(b, c))
print(total)

from math import gcd

k = int(eval(input()))
total = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        t = gcd(a, b)
        for c in range(1, k + 1):
            # print(a, b, c, gcd(a, gcd(b, c)))
            total += gcd(t, c)
print(total)  # sample_02 1982 ms

-# ABC162C -from fractions import gcd +        t = gcd(a, b) -            total += gcd(a, gcd(b, c)) -print(total) +            total += gcd(t, c) +print(total)  # sample_02 1982 ms