# コードテストする

from fractions import gcd

K = int(eval(input()))

ans = 0

gcd_list = {}

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

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

        gcd_list[i, j] = gcd(i, j)



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

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

        hoge = gcd_list[(i, j)]

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

            ans += gcd_list[(hoge, k)]

print(ans)

from math import gcd

K = int(eval(input()))

ans = 0

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

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

        tmp = gcd(i, j)

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

            ans += gcd(tmp, k)

print(ans)

# コードテストする
from fractions import gcd

K = int(eval(input()))
ans = 0
gcd_list = {}
for i in range(1, K + 1):
    for j in range(1, K + 1):
        gcd_list[i, j] = gcd(i, j)
for i in range(1, K + 1):
    for j in range(1, K + 1):
        hoge = gcd_list[(i, j)]
        for k in range(1, K + 1):
            ans += gcd_list[(hoge, k)]
print(ans)

from math import gcd

K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        tmp = gcd(i, j)
        for k in range(1, K + 1):
            ans += gcd(tmp, k)
print(ans)

-# コードテストする -from fractions import gcd +from math import gcd -gcd_list = {} -        gcd_list[i, j] = gcd(i, j) -for i in range(1, K + 1): -    for j in range(1, K + 1): -        hoge = gcd_list[(i, j)] +        tmp = gcd(i, j) -            ans += gcd_list[(hoge, k)] +            ans += gcd(tmp, k)