import math

n = int(eval(input()))



ans = 0

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

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

    temp = math.gcd(i,j)

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

      ans += math.gcd(temp,k)

print(ans)
import math

N = int(eval(input()))

ans = 0

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

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

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

      temp = math.gcd(i,j)

      temp = math.gcd(temp,k)

      ans += temp

print(ans)
import math

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

import math

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

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