k = int(eval(input()))



from math import gcd

ans = 0

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

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

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

            ans += gcd(a, gcd(b, c))

print(ans)
k = int(eval(input()))



from math import gcd

ans = 0

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

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

        ab = gcd(a, b)

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

            ans += gcd(ab, c)

print(ans)			
k = int(eval(input()))
from math import gcd

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

k = int(eval(input()))
from math import gcd

ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        ab = gcd(a, b)
        for c in range(1, k + 1):
            ans += gcd(ab, c)
print(ans)

+        ab = gcd(a, b) -            ans += gcd(a, gcd(b, c)) +            ans += gcd(ab, c)