import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
data=int(input())
result = [[i+1, j+1, k+1] for i in range(data) for j in range(data) for k in range(data)]

ans=0
#print(result)

for n in result:
  ans+=gcd(n[0],n[1],n[2])
  
print(ans)
  