let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let ans = ref 0;;
let () =
  Scanf.scanf "%d\n" @@ fun k ->
  for i = k downto 1 do
    for j = k downto 1 do
      for l = k downto 1 do
        ans := (gcd i (gcd j l)) + !ans
      done
    done
  done;
  Printf.printf "%d\n" !ans