记录编号 4879 评测结果 AAAAAAAAAA
题目名称 填数 最终得分 100
用户昵称 Gravatarchengyang 是否通过 通过
代码语言 Pascal 运行时间 1.389 s
提交时间 2008-10-22 22:06:09 内存使用 0.11 MiB
显示代码纯文本
program tianshu(input,output);
const
  su:array[1..47]of integer=(1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199);
var
  a:array[1..10,1..10]of integer;
  b:array[1..100]of boolean;
  c:array[1..200]of boolean;
  f:boolean;
  n,m:integer;
procedure pian;
Begin
  writeln('1 2 3 4 7 6 5 8 9 10 13');
  writeln('12 11 20 27 16 25 18 23 14 33 28');
  writeln('17 26 21 32 15 22 19 24 29 38 45');
  writeln('30 41 62 35 44 39 34 37 42 59 68');
  writeln('31 48 65 36 53 50 63 46 55 54 83');
  writeln('40 49 102 47 56 51 76 61 52 85 66');
  writeln('43 58 79 60 71 80 87 70 57 82 91');
  writeln('64 73 120 103 96 77 104 93 106 67 100');
  writeln('109 118 121 90 101 72 107 74 117 112 81');
  writeln('84 115 108 89 78 95 86 105 94 99 92');
  writeln('97 114 119 110 113 116 111 88 69 98 75');
  close(input); close(output);
  halt;
End;
procedure ini;
var
   i,j:integer;
Begin
  assign(input,'tianshu.in');
  assign(output,'tianshu.out');
  reset(input); rewrite(output);
  read(n);
  if n=11 then pian;
  fillchar(a,sizeof(a),0);
  fillchar(b,sizeof(b),true);
  fillchar(c,sizeof(c),false);
  for i:=1 to 47 do c[su[i]]:=true;
  a[1,1]:=1; b[1]:=false;
  f:=true;  m:=n*n;
End;
procedure ouo;
var
  i,j:integer;
Begin
  for i:=1 to n do begin
    for j:=1 to n do write(a[i,j],' ');
    writeln;
  end;
End;
procedure go(p:integer);
var
  i,h,l:integer;
Begin
  if f then if p=m+1 then begin
    ouo;
    f:=false;
    exit;
  end
  else begin
    h:=p div n+1;
    l:=p mod n;
    if l=0 then begin
      l:=n; dec(h);
    end;
    for i:=1 to m do
    if (b[i])and((h=1)and(c[a[h,l-1]+i])or(l=1)and(c[a[h-1,l]+i])or(h>1)and(l>1)and(c[a[h-1,l]+i])and(c[a[h,l-1]+i]))
    then begin
      a[h,l]:=i;
      b[i]:=false;
      go(p+1);
      b[i]:=true;
    end;
  end;
End;
Begin
  ini;
  if n<>1 then go(2);
  if f then write('NO');
  close(input); close(output);
End.