defmodule Main do
    def gcd3(a, b, c) do
        Integer.gcd(a, b) |> Integer.gcd(c)
    end
    def main do
        k = IO.read(:line)
        |> String.trim
        |> String.to_integer

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