import math

from functools import reduce



K = int(eval(input()))

total = 0





def gcd_list(*numbers):

    return reduce(math.gcd, numbers)





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

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

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

            s = [i, j, k]

            if i == j == k:

                total += gcd_list(*s)

            elif i == j and j != k:

                total += gcd_list(*s) * 3

            elif i != j and j == k:

                total += gcd_list(*s) * 3

            else:

                total += gcd_list(*s) * 6



print(total)

import math



K = int(eval(input()))

ans = 0

tmp = {}



for i in range(201):

    tmp[i] = 0



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

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

        tmp[math.gcd(i, j)] += 1



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

    for key in list(tmp.keys()):

        ans += math.gcd(key, k) * tmp[key]

print(ans)

import math
from functools import reduce

K = int(eval(input()))
total = 0


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


for i in range(1, K + 1):
    for j in range(1, i + 1):
        for k in range(1, j + 1):
            s = [i, j, k]
            if i == j == k:
                total += gcd_list(*s)
            elif i == j and j != k:
                total += gcd_list(*s) * 3
            elif i != j and j == k:
                total += gcd_list(*s) * 3
            else:
                total += gcd_list(*s) * 6
print(total)

import math

K = int(eval(input()))
ans = 0
tmp = {}
for i in range(201):
    tmp[i] = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        tmp[math.gcd(i, j)] += 1
for k in range(1, K + 1):
    for key in list(tmp.keys()):
        ans += math.gcd(key, k) * tmp[key]
print(ans)

-from functools import reduce -total = 0 - - -def gcd_list(*numbers): -    return reduce(math.gcd, numbers) - - +ans = 0 +tmp = {} +for i in range(201): +    tmp[i] = 0 -    for j in range(1, i + 1): -        for k in range(1, j + 1): -            s = [i, j, k] -            if i == j == k: -                total += gcd_list(*s) -            elif i == j and j != k: -                total += gcd_list(*s) * 3 -            elif i != j and j == k: -                total += gcd_list(*s) * 3 -            else: -                total += gcd_list(*s) * 6 -print(total) +    for j in range(1, K + 1): +        tmp[math.gcd(i, j)] += 1 +for k in range(1, K + 1): +    for key in list(tmp.keys()): +        ans += math.gcd(key, k) * tmp[key] +print(ans)