from math import gcd

K = int(eval(input()))

 

c = 0

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

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

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

            a = gcd(gcd(i,j), l)

            c += a

 

print(c)
from math import gcd

K = int(eval(input()))

 

c = 0

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

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

        k = gcd(i,j)

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

            a = gcd(k, l)

            c += a

print(c)
from math import gcd

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

from math import gcd

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

+        k = gcd(i, j) -            a = gcd(gcd(i, j), l) +            a = gcd(k, l)