import math

ans = 0

N = int(eval(input()))

for i in range(N):

    for j in range(N):

        for k in range(N):

            ans += math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))

print(ans)
import math

ans = 0

N = int(eval(input()))

if N <= 5:

  for i in range(N):

    for j in range(N):

        for k in range(N):

            ans += math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))

else:

    for i in range(N):

        ans += i+1

    for i in range(N-1):

        for j in range(i+1,N):

            ans += 6*math.gcd(i+1,j+1)

    for i in range(N-2):

        for j in range(i+1,N-1):

            for k in range(j+1,N):

                ans += 6*math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))

print(ans)
import math

ans = 0
N = int(eval(input()))
for i in range(N):
    for j in range(N):
        for k in range(N):
            ans += math.gcd(math.gcd(i + 1, j + 1), math.gcd(j + 1, k + 1))
print(ans)

import math

ans = 0
N = int(eval(input()))
if N <= 5:
    for i in range(N):
        for j in range(N):
            for k in range(N):
                ans += math.gcd(math.gcd(i + 1, j + 1), math.gcd(j + 1, k + 1))
else:
    for i in range(N):
        ans += i + 1
    for i in range(N - 1):
        for j in range(i + 1, N):
            ans += 6 * math.gcd(i + 1, j + 1)
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            for k in range(j + 1, N):
                ans += 6 * math.gcd(math.gcd(i + 1, j + 1), math.gcd(j + 1, k + 1))
print(ans)

-for i in range(N): -    for j in range(N): -        for k in range(N): -            ans += math.gcd(math.gcd(i + 1, j + 1), math.gcd(j + 1, k + 1)) +if N <= 5: +    for i in range(N): +        for j in range(N): +            for k in range(N): +                ans += math.gcd(math.gcd(i + 1, j + 1), math.gcd(j + 1, k + 1)) +else: +    for i in range(N): +        ans += i + 1 +    for i in range(N - 1): +        for j in range(i + 1, N): +            ans += 6 * math.gcd(i + 1, j + 1) +    for i in range(N - 2): +        for j in range(i + 1, N - 1): +            for k in range(j + 1, N): +                ans += 6 * math.gcd(math.gcd(i + 1, j + 1), math.gcd(j + 1, k + 1))