local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end
local r = 0
local k = io.read("*n")
for i = 1, k do
  for j = 1, k do
    local g = getgcd(i, j)
    for q = 1, k do
      r = r + getgcd(g, q)
    end
  end
end
print(r)
