let k = Scanf.sscanf (read_line ()) "%d" @@ fun k -> k

let rec gcd x y = if y = 0 then x else gcd y (x mod y)

let () =
  let ans = ref 0 in
  for a = 1 to k do for b = 1 to k do for c = 1 to k do
    ans := !ans + gcd a (gcd b c)
  done done done;
  Printf.printf "%d\n" !ans