from  math import  gcd

K = int(eval(input()))



ans = 0

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

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

        for l in range(1, K + 1):

            ans  += gcd(i, gcd(j, l))

            

            

print(ans)

K = int(eval(input()))



def func_gcd(a, b):

    if b > a:

        a, b = b, a

    

    while b > 0:

        r = a % b

        a = b

        b = r



    return a



ans = 0

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

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

        for l in range(1, K + 1):

            temp = func_gcd(j, l)

            temp2= func_gcd(i, temp)

            ans += temp2



print(ans)

from math import gcd

K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for l in range(1, K + 1):
            ans += gcd(i, gcd(j, l))
print(ans)

K = int(eval(input()))


def func_gcd(a, b):
    if b > a:
        a, b = b, a
    while b > 0:
        r = a % b
        a = b
        b = r
    return a


ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for l in range(1, K + 1):
            temp = func_gcd(j, l)
            temp2 = func_gcd(i, temp)
            ans += temp2
print(ans)

-from math import gcd +K = int(eval(input())) -K = int(eval(input())) + +def func_gcd(a, b): +    if b > a: +        a, b = b, a +    while b > 0: +        r = a % b +        a = b +        b = r +    return a + + -            ans += gcd(i, gcd(j, l)) +            temp = func_gcd(j, l) +            temp2 = func_gcd(i, temp) +            ans += temp2