from math import gcd



K=int(eval(input()))

sum=0



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

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

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

      tmp= gcd(i,j)

      sum += gcd(tmp,k)

      

print(sum)

from math import gcd



K=int(eval(input()))

sum=0



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

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

    tmp= gcd(i,j)

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

      sum += gcd(tmp,k)

      

print(sum)

from math import gcd

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

from math import gcd

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

+        tmp = gcd(i, j) -            tmp = gcd(i, j)