from math import gcd

k=int(eval(input()))

ans=0

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

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

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

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

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):

        x=gcd(i,j)

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

            ans+=gcd(x,l)

print(ans)
from math import gcd

k = int(eval(input()))
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            ans += gcd(gcd(a, b), c)
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):
        x = gcd(i, j)
        for l in range(1, k + 1):
            ans += gcd(x, l)
print(ans)

-for a in range(1, k + 1): -    for b in range(1, k + 1): -        for c in range(1, k + 1): -            ans += gcd(gcd(a, b), c) +for i in range(1, k + 1): +    for j in range(1, k + 1): +        x = gcd(i, j) +        for l in range(1, k + 1): +            ans += gcd(x, l)