from math import gcd

n = int(eval(input()))

ans = 0



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

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

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

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

print(ans)
from math import gcd

n = int(eval(input()))

ans = 0



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

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

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

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

print(ans)
from math import gcd

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

from math import gcd

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

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