program conprime(input,output);
var
a:array[1..10000]of integer;
s:integer;
procedure sushu;
var i,j:integer; b:boolean;
begin
s:=0;
for i:=2 to 10000 do begin
b:=true;
for j:=2 to trunc(sqrt(i)) do
if i mod j=0 then b:=false;
if b then begin inc(s);a[s]:=i;end;
end;
end;
procedure main;
var i,j,tot,num,n:longint;
begin
assign(input,'conprime.in');assign(output,'conprime.out');
reset(input);rewrite(output);
readln(n);
while n<>0 do begin
tot:=0; i:=1; j:=1; num:=2;
while i<=j do begin
if num=n then begin inc(tot); num:=num-a[i]; inc(i); end
else if num<n then begin inc(j); num:=num+a[j]; end
else if num>n then begin num:=num-a[i]; inc(i); end;
if (i>s) or (j>s) then break;
end;
writeln(tot);
readln(n);
end;
close(input);close(output);
end;
begin
sushu;
main;
end.