import math

K = int(input())
ans = 0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      temp = math.gcd(i, j)
      temp2 = math.gcd(temp, k)
      ans = temp2 + ans

print(ans)
