from math import gcd

k = int(eval(input()))

ans = 0

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

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

        t = gcd(a, b)

        if t == 1:

            ans += k

            continue

        for c in range(1, k+1): ans += gcd(t, c)

print(ans)
from math import gcd

k = int(eval(input()))

ar = [0] * 41000

for i in range(1, 201):

    for j in range(1, 201): ar[i*200+j] = gcd(i, j)



ans = 0

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

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

        d = ar[a*200+b]

        if d == 1:

            ans += k

            continue

        for c in range(1, k+1): ans += ar[d*200+c]

print(ans)



from math import gcd

k = int(eval(input()))
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        t = gcd(a, b)
        if t == 1:
            ans += k
            continue
        for c in range(1, k + 1):
            ans += gcd(t, c)
print(ans)

from math import gcd

k = int(eval(input()))
ar = [0] * 41000
for i in range(1, 201):
    for j in range(1, 201):
        ar[i * 200 + j] = gcd(i, j)
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        d = ar[a * 200 + b]
        if d == 1:
            ans += k
            continue
        for c in range(1, k + 1):
            ans += ar[d * 200 + c]
print(ans)

+ar = [0] * 41000 +for i in range(1, 201): +    for j in range(1, 201): +        ar[i * 200 + j] = gcd(i, j) -        t = gcd(a, b) -        if t == 1: +        d = ar[a * 200 + b] +        if d == 1: -            ans += gcd(t, c) +            ans += ar[d * 200 + c]