import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random

import sys

from functools import reduce

from collections import deque, defaultdict, Counter; from heapq import heappush, heappop

from itertools import permutations, combinations, product, accumulate, groupby

from bisect import bisect_left, bisect_right, insort_left, insort_right

from operator import itemgetter as ig

sys.setrecursionlimit(10 ** 7)

inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()

eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7

dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]

"""for dx, dy in dd:

        nx = j + dx; ny = i + dy

            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))

def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint

def ws(): return sys.stdin.readline().split()

def i(): return int(sys.stdin.readline())

def s(): return eval(input())

def s_list(): return list(eval(input()))

def hi(n): return [i() for _ in range(n)]

def hs(n): return [s() for _ in range(n)]#HeightString

def mi(n): return [wi() for _ in range(n)]#MatrixInt

def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid

def mip(n): return [wip() for _ in range(n)]

def ms(n): return [ws() for _ in range(n)]

def grid(n): return [s_list() for _ in range(n)]



def gcd(a,b):

    if b == 0:

        return a

    return gcd(b, a % b)



def gcd_list(numbers):

    return reduce(gcd, numbers)



K = i()



sigma = 0

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

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

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

            sigma += gcd_list([a, b, c])



print(sigma)
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random

import sys

from functools import reduce

from collections import deque, defaultdict, Counter; from heapq import heappush, heappop

from itertools import permutations, combinations, product, accumulate, groupby

from bisect import bisect_left, bisect_right, insort_left, insort_right

from operator import itemgetter as ig

sys.setrecursionlimit(10 ** 7)

inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()

eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7

dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]

"""for dx, dy in dd:

        nx = j + dx; ny = i + dy

            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))

def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint

def ws(): return sys.stdin.readline().split()

def i(): return int(sys.stdin.readline())

def s(): return eval(input())

def s_list(): return list(eval(input()))

def hi(n): return [i() for _ in range(n)]

def hs(n): return [s() for _ in range(n)]#HeightString

def mi(n): return [wi() for _ in range(n)]#MatrixInt

def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid

def mip(n): return [wip() for _ in range(n)]

def ms(n): return [ws() for _ in range(n)]

def grid(n): return [s_list() for _ in range(n)]



def gcd(a,b):

    if b == 0:

        return a

    return gcd(b, a % b)



def gcd_list(numbers):

    return reduce(gcd, numbers)



K = i()



sigma = 0

nums = [i for i in range(1, K + 1)]

for abc in itertools.combinations_with_replacement(nums, 3):  # 重複組み合わせ，200H3

    tmp = gcd_list(abc)

    abc_set = set(abc)

    sigma += int(tmp * (6 / (math.factorial(-len(abc_set) + 4))))



print(sigma)



"""

[1, 2, 3]

(1, 1)

(1, 2)

(1, 3)

(2, 2)

(2, 3)

(3, 3)

"""
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from functools import reduce
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig

sys.setrecursionlimit(10**7)
inf = 10**20
INF = float("INF")
ans = 0
tmp = 0
cnt = 0
ansli = []
tmpli = []
candili = []
stillset = set()
eps = 1.0 / 10**10
mod = 10**9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""


def wi():
    return list(map(int, sys.stdin.readline().split()))


def wip():
    return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint


def ws():
    return sys.stdin.readline().split()


def i():
    return int(sys.stdin.readline())


def s():
    return eval(input())


def s_list():
    return list(eval(input()))


def hi(n):
    return [i() for _ in range(n)]


def hs(n):
    return [s() for _ in range(n)]  # HeightString


def mi(n):
    return [wi() for _ in range(n)]  # MatrixInt


def num_grid(n):
    return [
        [int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)
    ]  # NumberGrid


def mip(n):
    return [wip() for _ in range(n)]


def ms(n):
    return [ws() for _ in range(n)]


def grid(n):
    return [s_list() for _ in range(n)]


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def gcd_list(numbers):
    return reduce(gcd, numbers)


K = i()
sigma = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            sigma += gcd_list([a, b, c])
print(sigma)

import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from functools import reduce
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig

sys.setrecursionlimit(10**7)
inf = 10**20
INF = float("INF")
ans = 0
tmp = 0
cnt = 0
ansli = []
tmpli = []
candili = []
stillset = set()
eps = 1.0 / 10**10
mod = 10**9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""


def wi():
    return list(map(int, sys.stdin.readline().split()))


def wip():
    return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint


def ws():
    return sys.stdin.readline().split()


def i():
    return int(sys.stdin.readline())


def s():
    return eval(input())


def s_list():
    return list(eval(input()))


def hi(n):
    return [i() for _ in range(n)]


def hs(n):
    return [s() for _ in range(n)]  # HeightString


def mi(n):
    return [wi() for _ in range(n)]  # MatrixInt


def num_grid(n):
    return [
        [int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)
    ]  # NumberGrid


def mip(n):
    return [wip() for _ in range(n)]


def ms(n):
    return [ws() for _ in range(n)]


def grid(n):
    return [s_list() for _ in range(n)]


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def gcd_list(numbers):
    return reduce(gcd, numbers)


K = i()
sigma = 0
nums = [i for i in range(1, K + 1)]
for abc in itertools.combinations_with_replacement(nums, 3):  # 重複組み合わせ，200H3
    tmp = gcd_list(abc)
    abc_set = set(abc)
    sigma += int(tmp * (6 / (math.factorial(-len(abc_set) + 4))))
print(sigma)
"""
[1, 2, 3]
(1, 1)
(1, 2)
(1, 3)
(2, 2)
(2, 3)
(3, 3)
"""

-for a in range(1, K + 1): -    for b in range(1, K + 1): -        for c in range(1, K + 1): -            sigma += gcd_list([a, b, c]) +nums = [i for i in range(1, K + 1)] +for abc in itertools.combinations_with_replacement(nums, 3):  # 重複組み合わせ，200H3 +    tmp = gcd_list(abc) +    abc_set = set(abc) +    sigma += int(tmp * (6 / (math.factorial(-len(abc_set) + 4)))) +""" +[1, 2, 3] +(1, 1) +(1, 2) +(1, 3) +(2, 2) +(2, 3) +(3, 3) +"""