# coding: utf-8

import sys

from math import gcd



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



K = ir()

answer = 0

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

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

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

            answer += gcd(a, gcd(b, c))



print(answer)

# coding: utf-8

import sys

import numpy as np



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



K = ir()

A = np.arange(1, K+1, dtype=np.int32)

B = np.gcd.outer(np.gcd.outer(A, A), A)

answer = B.sum()

print(answer)

# coding: utf-8
import sys
from math import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
K = ir()
answer = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            answer += gcd(a, gcd(b, c))
print(answer)

# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
K = ir()
A = np.arange(1, K + 1, dtype=np.int32)
B = np.gcd.outer(np.gcd.outer(A, A), A)
answer = B.sum()
print(answer)

-from math import gcd +import numpy as np -answer = 0 -for a in range(1, K + 1): -    for b in range(1, K + 1): -        for c in range(1, K + 1): -            answer += gcd(a, gcd(b, c)) +A = np.arange(1, K + 1, dtype=np.int32) +B = np.gcd.outer(np.gcd.outer(A, A), A) +answer = B.sum()