program conprime;
var
i,j,k,l,n,m:longint;
a,b:array[0..10001]of longint;
function pan(x:longint):boolean;
var
i,j:longint;
begin
for i:=2 to trunc(sqrt(x)) do
if (x mod i)=0 then exit(false);
exit(true);
end;
function min(x,y:longint):longint;
begin
if x>y then exit(y)
else exit(x);
end;
begin
assign(input,'conprime.in');
reset(input);
assign(output,'conprime.out');
rewrite(output);
a[0]:=2;
a[1]:=0;
a[2]:=2;
for i:=3 to 10000 do
if pan(i) then
begin
inc(a[0]);
a[a[0]]:=i;
end;
for i:=2 to a[0] do
a[i]:=a[i-1]+a[i];
for i:=1 to 10000 do
b[i]:=0;
for i:=a[0] downto 2 do
for j:=i-1 downto 1 do
if a[i]-a[j]<10000 then
inc(b[a[i]-a[j]]);
readln(n);
while n<>0 do
begin
writeln(b[n]);
readln(n);
end;
close(input);
close(output);
end.