记录编号 15043 评测结果 AAAAAA
题目名称 [HAOI 2004模拟]数列问题 最终得分 100
用户昵称 Gravatarbing 是否通过 通过
代码语言 Pascal 运行时间 1.051 s
提交时间 2009-11-09 16:40:09 内存使用 0.12 MiB
显示代码纯文本
program bing;
var
 f1,f2:text;
 n:integer;
 s:longint;
 a:array[0..50] of integer;
 b:array[0..50] of boolean;
 c:array[1..100] of boolean;
 d:array[0..50,0..50] of integer;
procedure scss;
var
 i,j:Integer;
 f:boolean;
begin
 fillchar(c,sizeof(c),false);
 c[2]:=true;
 for i:=3 to 100 do
 begin
  f:=true;
  for j:=2 to trunc(sqrt(i)) do
  if i mod j=0 then begin f:=false;break;end;
  if f then c[i]:=true;
 end;
end;
procedure init;
var
 i,j:integer;
begin
 assign(f1,'dfs3.in');reset(f1);
 assign(f2,'dfs3.out');rewrite(f2);
 readln(f1,n);
 s:=0;
 fillchar(a,sizeof(a),0);
 fillchar(b,sizeof(b),true);
 scss;
 for i:=0 to n do
 for j:=1 to n do
 if ((i<>j)and(c[i+j]))or(i=0) then
 begin
  inc(d[i,0]);
  d[i,d[i,0]]:=j;
 end;
end;
procedure print;
var
 i:integer;
begin
 for i:=1 to n do write(f2,a[i],' ');
 writeln(f2);
end;
procedure nb(x:integer);
var
 i:integer;
begin
 for i:=1 to d[a[x-1],0] do
 if b[d[a[x-1],i]] then
 begin
  b[d[a[x-1],i]]:=false;
  a[x]:=d[a[x-1],i];
  if x=n then begin inc(s);print;end
  else nb(x+1);
  b[d[a[x-1],i]]:=true;
 end;
end;
begin
 init;
 nb(1);
 writeln(f2,s);
 close(f1);close(f2);
end.