import math

k=int(eval(input()))

ans=0

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

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

        ij=math.gcd(i,j)

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

            ans+=math.gcd(ij,k)

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

        ij=gcd(i,j)

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

            ans+=gcd(ij,k)

print(ans)
import math

k = int(eval(input()))
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        ij = math.gcd(i, j)
        for k in range(1, k + 1):
            ans += math.gcd(ij, k)
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):
        ij = gcd(i, j)
        for k in range(1, k + 1):
            ans += gcd(ij, k)
print(ans)

-import math +from math import gcd -        ij = math.gcd(i, j) +        ij = gcd(i, j) -            ans += math.gcd(ij, k) +            ans += gcd(ij, k)