# 3重ループでテスト



from functools import reduce



k = int(eval(input()))



def gcd(a, b):

    # 最大公約数

    while b:

        a, b = b, a % b

    return a



def gcds(*nums):

	return reduce(gcd, nums)



res = 0

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

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

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

			res += gcds(a, b, c)



print(res)
from math import gcd



k = int(eval(input()))



gcd_sum = [0] * 201

res = 0



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

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

		gcd_sum[i] += gcd(i, j)



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

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

		g = gcd(a, b)

		res += gcd_sum[g]



print(res)
# 3重ループでテスト
from functools import reduce

k = int(eval(input()))


def gcd(a, b):
    # 最大公約数
    while b:
        a, b = b, a % b
    return a


def gcds(*nums):
    return reduce(gcd, nums)


res = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            res += gcds(a, b, c)
print(res)

from math import gcd

k = int(eval(input()))
gcd_sum = [0] * 201
res = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd_sum[i] += gcd(i, j)
for a in range(1, k + 1):
    for b in range(1, k + 1):
        g = gcd(a, b)
        res += gcd_sum[g]
print(res)

-# 3重ループでテスト -from functools import reduce +from math import gcd - - -def gcd(a, b): -    # 最大公約数 -    while b: -        a, b = b, a % b -    return a - - -def gcds(*nums): -    return reduce(gcd, nums) - - +gcd_sum = [0] * 201 +for i in range(1, k + 1): +    for j in range(1, k + 1): +        gcd_sum[i] += gcd(i, j) -        for c in range(1, k + 1): -            res += gcds(a, b, c) +        g = gcd(a, b) +        res += gcd_sum[g]