let for_range s e step f =
  let rec loop i =
    if i <= e then begin f i;loop (i + step) end
  in loop s;;
 
let sieve num =
  let p = Array.init num (fun x -> x mod 2) in
  let rec loop i =
    if i*i < num then
      begin
        if p.(i) = 1 then for_range (i*i) num (i*2) (fun x -> p.(x) <- 0);
        loop (i+2)
      end
  in
  p.(0) <- 0; p.(1)<-(0);p.(2)<-1;loop 3;p
;;
 
let () =
  let p = sieve 50000 in
  let rec read () =
    let n = read_int () in
    if n = 0 then ()
    else
      begin
        let count = ref 0 in
        if n = 4 then count := 1
        else
          if n mod 2 = 1 then
            if p.(n-2) = 1 then incr count else ()
          else
            begin
              let m = n/2 in
              for_range 3 m 2 (fun i -> if p.(i)=1 && p.(n-i)=1 then incr count)
            end
        ;print_int !count;print_newline ();read ()
      end
  in read ()
;;