from math import gcd

k=int(eval(input()))

        

r=0

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

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

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

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

print(r)
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):

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

 

print(total)
from math import gcd

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

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):
            total += gcd(gcd(a, b), c)
print(total)

-r = 0 -for i in range(1, k + 1): -    for j in range(1, k + 1): -        for l in range(1, k + 1): -            r += gcd(gcd(i, j), l) -print(r) +total = 0 +for a in range(1, k + 1): +    for b in range(1, k + 1): +        for c in range(1, k + 1): +            total += gcd(gcd(a, b), c) +print(total)