import math

from functools import reduce



def gcd(*numbers):

    return reduce(math.gcd, numbers)



comb_count = {1:1, 2:3, 3:6}

k = int(eval(input()))

ans = 0

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

    for b in range(a, k+1):

        for c in range(b, k+1):

            ans += gcd(a, b, c) * comb_count[len(set([a, b, c]))]

print(ans)
from collections import defaultdict



def gcd(a, b):

    if b == 0:

        return a

    else:

        return gcd(b, a%b)



gcd_cnt = defaultdict(int)

ans = 0

k = int(eval(input()))

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

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

        gcd_cnt[gcd(a, b)] += 1



for key in gcd_cnt:

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

        ans += gcd(c, key) * gcd_cnt[key]

print(ans)
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


comb_count = {1: 1, 2: 3, 3: 6}
k = int(eval(input()))
ans = 0
for a in range(1, k + 1):
    for b in range(a, k + 1):
        for c in range(b, k + 1):
            ans += gcd(a, b, c) * comb_count[len(set([a, b, c]))]
print(ans)

from collections import defaultdict


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


gcd_cnt = defaultdict(int)
ans = 0
k = int(eval(input()))
for a in range(1, k + 1):
    for b in range(1, k + 1):
        gcd_cnt[gcd(a, b)] += 1
for key in gcd_cnt:
    for c in range(1, k + 1):
        ans += gcd(c, key) * gcd_cnt[key]
print(ans)

-import math -from functools import reduce +from collections import defaultdict -def gcd(*numbers): -    return reduce(math.gcd, numbers) +def gcd(a, b): +    if b == 0: +        return a +    else: +        return gcd(b, a % b) -comb_count = {1: 1, 2: 3, 3: 6} +gcd_cnt = defaultdict(int) +ans = 0 -ans = 0 -    for b in range(a, k + 1): -        for c in range(b, k + 1): -            ans += gcd(a, b, c) * comb_count[len(set([a, b, c]))] +    for b in range(1, k + 1): +        gcd_cnt[gcd(a, b)] += 1 +for key in gcd_cnt: +    for c in range(1, k + 1): +        ans += gcd(c, key) * gcd_cnt[key]