def gcd(x, y):
  if x % y == 0:
    return y
  
  return gcd(y, x % y)


K = int(input())
count = 0
ab = []

for a in range(1, K+1):
  for b in range(1, K+1):
    ab.append(gcd(a, b))

for c in range(1, K+1):
  for i in ab:
    count += gcd(ab, c)

print(count)