def gcd(a, b):

    if a < b:

        a, b = b, a

    while b:

        a, b = b, a % b

    return a



k = int(eval(input()))

sum = 0



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

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

        gcd_ij = gcd(i, j)

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

            sum += gcd(gcd_ij, k)

print(sum)
from math import gcd

k = int(eval(input()))

sum = 0

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

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

        gcd_ij = gcd(i, j)

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

            sum += gcd(gcd_ij, k)

print(sum)
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a


k = int(eval(input()))
sum = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd_ij = gcd(i, j)
        for k in range(1, k + 1):
            sum += gcd(gcd_ij, k)
print(sum)

from math import gcd

k = int(eval(input()))
sum = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd_ij = gcd(i, j)
        for k in range(1, k + 1):
            sum += gcd(gcd_ij, k)
print(sum)

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