比赛 暑假培训三 评测结果 AAAAAT
题目名称 数列问题 最终得分 83
用户昵称 zpl123 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-19 10:57:41
显示代码纯文本
program dfs3;
var
 n:integer;
 ss:array[2..99] of boolean;
 a:array[0..50] of 1..50;
 flag:array[1..50] of boolean;
 stack:array[0..50] of integer;
 f1,f2:text;
 i,p:integer;
 count:longint;

procedure prime;
 var
  i,j:integer;
  flag:boolean;
 begin
  fillchar(ss,sizeof(ss),false);
  for i:=2 to 99 do begin
   j:=2; flag:=true;
   while flag and (j<=sqrt(i)) do begin
    if i mod j=0 then flag:=false;
    inc(j);
   end;
   if flag then ss[i]:=true;
  end;
 end;

procedure ini;
var
 i:integer;
begin
 assign(f1,'dfs3.in');assign(f2,'dfs3.out');
 reset(f1);  rewrite(f2);
 readln(f1,n);
 close(f1);
 prime;
 fillchar(flag,sizeof(flag),true);
 count:=0;
end;

procedure print;
 var
  i:integer;
 begin
  for i:=1 to p do begin
   write(f2,a[i]);
   if i<p then write(f2,' ');
  end;
  writeln(f2);
  inc(count);
 end;

procedure try(x:integer);
 var
  i,j,k:integer;
 begin
  i:=x;k:=0;p:=1;
  a[p]:=i;flag[i]:=false;
  repeat
   inc(k);
   while k<=n do begin
    if flag[k] and ss[i+k] then begin
       inc(p);
       a[p]:=k;flag[k]:=false;
       i:=k;
       if p=n  then print  else k:=0;
    end;
    inc(k);
   end;
   k:=a[p];
   p:=p-1;flag[i]:=true;
   if p<>0 then i:=a[p];
  until p=0;
 end;

begin
ini;
for i:=1 to n do try(i);
write(f2,count);
close(f2);
end.