import math



a=int(eval(input()))



t=0

"""

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

  for j in range(i,a+1):

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

      

      print(i,j,k)



      if i==j and j==k:

        t+=math.gcd(math.gcd(i,j),k)

      else:

        t+=(math.gcd(math.gcd(i,j),k)*3)



print(t)

"""



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

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

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

      t+=math.gcd(math.gcd(i,j),k)

print(t)
import math



a=int(eval(input()))



t=0



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

  for j in range(i,a+1):

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

      

      #print(i,j,k)



      if i==j and j==k:

        t+=math.gcd(math.gcd(i,j),k)

      elif i!=j and j!=k and i!=k:

        t+=(math.gcd(math.gcd(i,j),k)*6)

      else:

        t+=(math.gcd(math.gcd(i,j),k)*3)



print(t)
import math

a = int(eval(input()))
t = 0
"""
for i in range(1,a+1):
  for j in range(i,a+1):
    for k in range(j,a+1):
      print(i,j,k)
      if i==j and j==k:
        t+=math.gcd(math.gcd(i,j),k)
      else:
        t+=(math.gcd(math.gcd(i,j),k)*3)
print(t)
"""
for i in range(1, a + 1):
    for j in range(1, a + 1):
        for k in range(1, a + 1):
            t += math.gcd(math.gcd(i, j), k)
print(t)

import math

a = int(eval(input()))
t = 0
for i in range(1, a + 1):
    for j in range(i, a + 1):
        for k in range(j, a + 1):
            # print(i,j,k)
            if i == j and j == k:
                t += math.gcd(math.gcd(i, j), k)
            elif i != j and j != k and i != k:
                t += math.gcd(math.gcd(i, j), k) * 6
            else:
                t += math.gcd(math.gcd(i, j), k) * 3
print(t)

-""" -for i in range(1,a+1): -  for j in range(i,a+1): -    for k in range(j,a+1): -      print(i,j,k) -      if i==j and j==k: -        t+=math.gcd(math.gcd(i,j),k) -      else: -        t+=(math.gcd(math.gcd(i,j),k)*3) +for i in range(1, a + 1): +    for j in range(i, a + 1): +        for k in range(j, a + 1): +            # print(i,j,k) +            if i == j and j == k: +                t += math.gcd(math.gcd(i, j), k) +            elif i != j and j != k and i != k: +                t += math.gcd(math.gcd(i, j), k) * 6 +            else: +                t += math.gcd(math.gcd(i, j), k) * 3 -""" -for i in range(1, a + 1): -    for j in range(1, a + 1): -        for k in range(1, a + 1): -            t += math.gcd(math.gcd(i, j), k) -print(t)