import sys

input = sys.stdin.readline

from itertools import *

from functools import *

from collections import *

from heapq import heapify, heappop, heappush, heappushpop



from math import gcd



INF = float('inf')

NIL = - 1



N = int(eval(input()))

ans = 0

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

    if i == 1:

        ans += N ** 2

        continue

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

        if j == 1:

            ans += N

            continue

        tmp = gcd(i, j)

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

            ans += gcd(tmp, k)

print(ans)





import sys

input = sys.stdin.readline

from itertools import *

from functools import *

from collections import *

from heapq import heapify, heappop, heappush, heappushpop



from math import gcd



INF = float('inf')

NIL = - 1



N = int(eval(input()))

ans = 0

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

    if i == 1:

        ans += N ** 2

        continue

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

        if j == 1:

            ans += N

            continue

        tmp = gcd(i, j)

        if tmp == 1:

            ans += N 

            continue

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

            if k == 1:

                ans += 1

                continue

            ans += gcd(tmp, k)

print(ans)





import sys

input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop
from math import gcd

INF = float("inf")
NIL = -1
N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
    if i == 1:
        ans += N**2
        continue
    for j in range(1, N + 1):
        if j == 1:
            ans += N
            continue
        tmp = gcd(i, j)
        for k in range(1, N + 1):
            ans += gcd(tmp, k)
print(ans)

import sys

input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop
from math import gcd

INF = float("inf")
NIL = -1
N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
    if i == 1:
        ans += N**2
        continue
    for j in range(1, N + 1):
        if j == 1:
            ans += N
            continue
        tmp = gcd(i, j)
        if tmp == 1:
            ans += N
            continue
        for k in range(1, N + 1):
            if k == 1:
                ans += 1
                continue
            ans += gcd(tmp, k)
print(ans)

+        if tmp == 1: +            ans += N +            continue +            if k == 1: +                ans += 1 +                continue