open Printf
open Scanf

let rec gcd a b =
  if b = 0 then a
  else gcd b (a mod b)

let solve n =
  let rec loop i j k sm =
    if i > n then sm
    else if j > n then loop (i + 1) 1 1 sm
    else if k > n then loop i (j + 1) 1 sm
    else loop i j (k + 1) (sm + gcd i (gcd j k)) in
  loop 1 1 1 0
   
let () =
  scanf "%d " solve |> printf "%d\n"
