let rec gcd n m =
  if m = 0 then n
  else gcd m (n mod m)

let () = Scanf.scanf "%d" @@ fun k ->
  Printf.printf "%d\n" @@
  Array.fold_left (Array.fold_left (Array.fold_left ( + ))) 0 @@
  Array.init k @@ fun a ->
    Array.init k @@ fun b ->
      Array.init k @@ fun c ->
        gcd (a + 1) (gcd (b + 1) (c + 1))