from math import gcd



k = int(eval(input())) + 1

ans = 0



for s in range(1, k):

    for t in range(s, k):

        for u in range(t, k):

            if (v := len(set([s, t, u]))) == 1:

                ans += gcd(gcd(s, t), u)

            elif v == 2:

                ans += gcd(gcd(s, t), u) * 3

            else:

                ans += gcd(gcd(s, t), u) * 6

print(ans)



from math import gcd



k = int(eval(input())) + 1

ans = 0



for s in range(1, k):

    for t in range(s, k):

        first = gcd(s, t)

        for u in range(t, k):

            if (v := len(set([s, t, u]))) == 1:

                ans += gcd(first, u)

            elif v == 2:

                ans += gcd(first, u) * 3

            else:

                ans += gcd(first, u) * 6

print(ans)



from math import gcd

k = int(eval(input())) + 1
ans = 0
for s in range(1, k):
    for t in range(s, k):
        for u in range(t, k):
            if (v := len(set([s, t, u]))) == 1:
                ans += gcd(gcd(s, t), u)
            elif v == 2:
                ans += gcd(gcd(s, t), u) * 3
            else:
                ans += gcd(gcd(s, t), u) * 6
print(ans)

from math import gcd

k = int(eval(input())) + 1
ans = 0
for s in range(1, k):
    for t in range(s, k):
        first = gcd(s, t)
        for u in range(t, k):
            if (v := len(set([s, t, u]))) == 1:
                ans += gcd(first, u)
            elif v == 2:
                ans += gcd(first, u) * 3
            else:
                ans += gcd(first, u) * 6
print(ans)

+        first = gcd(s, t) -                ans += gcd(gcd(s, t), u) +                ans += gcd(first, u) -                ans += gcd(gcd(s, t), u) * 3 +                ans += gcd(first, u) * 3 -                ans += gcd(gcd(s, t), u) * 6 +                ans += gcd(first, u) * 6