import math
k = int(input())
 
sum = 0
for x1 in range(1,k+1):
  for x2 in range(1,k+1):
    for x3 in range(1,k+1):
      for i in range(1, 2):
        ans = math.gcd(x1,x2)
        ans = math.gcd(ans,x3)
        sum += ans
 
print(sum)