def euclid(a, b):

    while b:

        a, b = b, a%b

    return a

  

K = int(eval(input()))



count=0

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

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

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

      if i == j and j == k:

        kake = 1

      elif i == j or j == k or i == k:

        kake = 3

      else:

        kake = 6

      count += euclid(euclid(i, j), k) * kake



print(count)
import numpy as np



K = int(eval(input()))

x = np.arange(1, K + 1)

nums = np.gcd.outer(np.gcd.outer(x, x), x)



print((np.sum(nums)))
def euclid(a, b):
    while b:
        a, b = b, a % b
    return a


K = int(eval(input()))
count = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            if i == j and j == k:
                kake = 1
            elif i == j or j == k or i == k:
                kake = 3
            else:
                kake = 6
            count += euclid(euclid(i, j), k) * kake
print(count)

import numpy as np

K = int(eval(input()))
x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)
print((np.sum(nums)))

-def euclid(a, b): -    while b: -        a, b = b, a % b -    return a - +import numpy as np -count = 0 -for i in range(1, K + 1): -    for j in range(i, K + 1): -        for k in range(j, K + 1): -            if i == j and j == k: -                kake = 1 -            elif i == j or j == k or i == k: -                kake = 3 -            else: -                kake = 6 -            count += euclid(euclid(i, j), k) * kake -print(count) +x = np.arange(1, K + 1) +nums = np.gcd.outer(np.gcd.outer(x, x), x) +print((np.sum(nums)))