let for_range s e step f =
  let rec loop i =
    if i > e then ()
    else
      begin f i;loop (i + step) end
  in loop s;;
let () =
  let num = 100 in
  let p = Array.init (num+1) (fun x -> x) and
      q = Array.init (num+1) (fun x -> 0) and
      j = ref 1
  in
  let rec loop i =
    if i*i < num then
      begin
        if p.(i) > 0 then
          begin
            p.(i*2) <- 0;
            for_range (i*3) num (i*2) (fun x -> p.(x) <- 0);
          end;
        loop (i+2)
      end
  in
  p.(0) <- 0; p.(1)<-(0);
  for_range 4 num 2 (fun x -> p.(x) <- 0);
  loop 3;
  for i = 1 to num-1 do
    if p.(i) > 0 then
      begin
        q.(!j) <- p.(i) + q.(!j-1);
        j:=!j+1;
      end;
  done;
  let rec read () =
    let n = read_int () in
    if n = 0 then ()
    else
      begin
        Printf.printf "%d\n" q.(n);
        read ();
      end;
  in read ();;