let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init (n + 1) @@ function
    | 0 -> 0
    | _ -> Scanf.scanf "%d " @@ fun a -> a in
  for i = n downto 1 do
    if
      ( > ) 0 @@
      Array.fold_left ( + ) 0 @@
      Array.init (n / i) (fun j -> as_.(i * (1 + j)))
    then
      for j = 1 to n / i do
        as_.(i * j) <- 0
      done
  done;
  Printf.printf "%d\n" @@ Array.fold_left ( + ) 0 as_
