let pn n =
  let pt = Array.make (n+1) 1 in
  pt.(0) <- 0;
  pt.(1) <- 0;
  let rec iter i =
    if i * i > n then Array.fold_left (+) 0 pt
    else
      if pt.(i) = 1 then
        let rec clr j =
          if j > n then ()
          else begin
              pt.(j) <- 0;
              clr (j+i)
            end in
        clr (i*i);
        iter (i+1)
      else
        iter (i+1)
  in iter 2
     
let () =
  let rec loop () =
    let n = try read_int () with _ -> 0 in
    if n = 0 then ()
    else begin
        pn n |> string_of_int |> print_endline;
        loop ()
      end
  in
  loop ()