defmodule Main do
    def main do
        k = IO.read(:line)
        |> String.trim
        |> String.to_integer

        x = for c<- (for a <- 1..k, b <- 1..k, do: Integer.gcd(a, b)), d <- 1..k, do: Integer.gcd(c, d)
        IO.puts Enum.sum(x)
    end
end