import math

K=int(eval(input()))

c = 0

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

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

    if math.gcd(i,j) == 1:

      c += K

    else:

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

        if i == j == k:

          c += i

        elif i == j:

          c += math.gcd(i,k)

        elif i == k:

          c += math.gcd(i,j)

        elif j == k:

          c += math.gcd(i,k)

        else:

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

print(c)
import math

K=int(eval(input()))

c = 0

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

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

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

      if i == j == k:

        c += i

      elif i == j:

        c += math.gcd(i,k)

      elif i == k:

        c += math.gcd(i,j)

      elif j == k:

        c += math.gcd(i,k)

      else:

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

print(c)
import math

K = int(eval(input()))
c = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        if math.gcd(i, j) == 1:
            c += K
        else:
            for k in range(1, K + 1):
                if i == j == k:
                    c += i
                elif i == j:
                    c += math.gcd(i, k)
                elif i == k:
                    c += math.gcd(i, j)
                elif j == k:
                    c += math.gcd(i, k)
                else:
                    c += math.gcd(math.gcd(i, j), k)
print(c)

import math

K = int(eval(input()))
c = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            if i == j == k:
                c += i
            elif i == j:
                c += math.gcd(i, k)
            elif i == k:
                c += math.gcd(i, j)
            elif j == k:
                c += math.gcd(i, k)
            else:
                c += math.gcd(math.gcd(i, j), k)
print(c)

-        if math.gcd(i, j) == 1: -            c += K -        else: -            for k in range(1, K + 1): -                if i == j == k: -                    c += i -                elif i == j: -                    c += math.gcd(i, k) -                elif i == k: -                    c += math.gcd(i, j) -                elif j == k: -                    c += math.gcd(i, k) -                else: -                    c += math.gcd(math.gcd(i, j), k) +        for k in range(1, K + 1): +            if i == j == k: +                c += i +            elif i == j: +                c += math.gcd(i, k) +            elif i == k: +                c += math.gcd(i, j) +            elif j == k: +                c += math.gcd(i, k) +            else: +                c += math.gcd(math.gcd(i, j), k)