
local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end


local k = io.read("*n")
local ret = 0
for a = 1, k do for b = 1, k do for c = 1, k do
  ret = ret + getgcd(a, getgcd(b, c))
end end end
print(ret)
