比赛 暑假培训三 评测结果 AAAAAT
题目名称 数列问题 最终得分 83
用户昵称 辨机ZN 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-19 10:21:37
显示代码纯文本
program ex(f1,f2);
 type
  zn=array [1..100] of boolean;
  ma=array [1..100] of integer;
  na=array [1..200] of integer;
 var
  a:zn; f1,f2:text; i,j,k,n,m,s:integer;
  ss:na;  flag,flag2:boolean; total:longint;
  c:ma;
 procedure sushu;
  var i:integer; flag:boolean;
  begin
   k:=2;
   for i:=5 to 100 do
    begin
     flag:=true;
     for j:=2 to trunc(sqrt(i)) do
       if i mod j =0 then
        begin
         flag:=false;
         break;
        end;
     if flag then
      begin
       inc(k);
       ss[k]:=i;
      end;
    end;
  end;
 procedure shuchu;
  var i,j:integer;
   begin
    for i:=1 to n-1 do write(f2,c[i],' ');
    writeln(f2,c[n]);
    inc(total);
   end;
 procedure try(step:integer);
  var i:integer; flag3:boolean;
  begin
  for i:=1 to n do
    begin
    flag3:=true;
    if a[i]=true
     then
      begin
        if step<>1 then
         begin
          s:=i+c[step-1]; m:=1;
          while (flag3)and(ss[m]<=trunc(sqrt(s))) do
           begin
            if s mod ss[m]=0 then flag3:=false
                             else inc(m);
           end;
         end;
         if flag3=true then
          begin
           a[i]:=false;
           c[step]:=i;
           if step<>n then
           try(step+1)
            else
            shuchu;
            a[i]:=true;
          end;
      end;
    end;
  end;
 begin
  assign(f1,'dfs3.in'); assign(f2,'dfs3.out');
  reset(f1); rewrite(f2);
  readln(f1,n);
  ss[1]:=2; ss[2]:=3;
  sushu;
  for i:=1 to 50 do a[i]:=true;
  total:=0;
  for i:=1 to 50 do c[i]:=0;
  try(1);
  writeln(f2,total);
  close(f1);
  close(f2);
 end.