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()))
import sys

def input(): return sys.stdin.readline().strip()

def mapint(): return list(map(int, input().split()))

sys.setrecursionlimit(10**9)



K = int(eval(input()))

from math import gcd

ans = 0

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

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

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

            ans += gcd(i, gcd(j, k))

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()))

import sys


def input():
    return sys.stdin.readline().strip()


def mapint():
    return list(map(int, input().split()))


sys.setrecursionlimit(10**9)
K = int(eval(input()))
from math import gcd

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            ans += gcd(i, gcd(j, k))
print(ans)

+import sys + + +def input(): +    return sys.stdin.readline().strip() + + +def mapint(): +    return list(map(int, input().split())) + + +sys.setrecursionlimit(10**9) +K = int(eval(input())) - -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())) +ans = 0 +for i in range(1, K + 1): +    for j in range(1, K + 1): +        for k in range(1, K + 1): +            ans += gcd(i, gcd(j, k)) +print(ans)