def GCD(a, b):

    return a if b == 0 else GCD(b, a % b)





k = int(eval(input()))



ans = 0

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

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

        ab = GCD(a, b)

        if ab == 1:

            ans += k

            continue

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

            ans += GCD(ab, 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):

        ab = gcd(a, b)

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

            ans += gcd(ab, c)



print(ans)

def GCD(a, b):
    return a if b == 0 else GCD(b, a % b)


k = int(eval(input()))
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        ab = GCD(a, b)
        if ab == 1:
            ans += k
            continue
        for c in range(1, k + 1):
            ans += GCD(ab, 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):
        ab = gcd(a, b)
        for c in range(1, k + 1):
            ans += gcd(ab, c)
print(ans)

-def GCD(a, b): -    return a if b == 0 else GCD(b, a % b) - +from math import gcd -        ab = GCD(a, b) -        if ab == 1: -            ans += k -            continue +        ab = gcd(a, b) -            ans += GCD(ab, c) +            ans += gcd(ab, c)