K = int(eval(input()))



from math import gcd

   

ans = 0

dic = {}

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

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

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

            time = len(set([i, j, k]))

            if time==3:

                t=6

            elif time==2:

                t=3

            else:

                t=1

            s = tuple(sorted([i, j, k]))

            if s in dic:

                ans += dic[s]

            else:

                a = gcd(gcd(i, j), k)

                ans += a*t

                dic[s] = a*t

                

print(ans)
from math import gcd



def solve():

  K = int(eval(input()))

  ans = 0

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

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

          a = gcd(i, j)

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

            ans += gcd(a, k)

  return ans

                

print((solve()))
K = int(eval(input()))
from math import gcd

ans = 0
dic = {}
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            time = len(set([i, j, k]))
            if time == 3:
                t = 6
            elif time == 2:
                t = 3
            else:
                t = 1
            s = tuple(sorted([i, j, k]))
            if s in dic:
                ans += dic[s]
            else:
                a = gcd(gcd(i, j), k)
                ans += a * t
                dic[s] = a * t
print(ans)

from math import gcd


def solve():
    K = int(eval(input()))
    ans = 0
    for i in range(1, K + 1):
        for j in range(1, K + 1):
            a = gcd(i, j)
            for k in range(1, K + 1):
                ans += gcd(a, k)
    return ans


print((solve()))

-K = int(eval(input())) -ans = 0 -dic = {} -for i in range(1, K + 1): -    for j in range(i, K + 1): -        for k in range(j, K + 1): -            time = len(set([i, j, k])) -            if time == 3: -                t = 6 -            elif time == 2: -                t = 3 -            else: -                t = 1 -            s = tuple(sorted([i, j, k])) -            if s in dic: -                ans += dic[s] -            else: -                a = gcd(gcd(i, j), k) -                ans += a * t -                dic[s] = a * t -print(ans) + +def solve(): +    K = int(eval(input())) +    ans = 0 +    for i in range(1, K + 1): +        for j in range(1, K + 1): +            a = gcd(i, j) +            for k in range(1, K + 1): +                ans += gcd(a, k) +    return ans + + +print((solve()))