记录编号 |
4545 |
评测结果 |
ATAAATAAAA |
题目名称 |
填数 |
最终得分 |
80 |
用户昵称 |
bing |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
7.108 s |
提交时间 |
2008-10-20 20:41:52 |
内存使用 |
0.11 MiB |
显示代码纯文本
program bing;
type
biao=array[1..10,1..10] of integer;
var
f1,f2:text;
n,s,k:integer;
a:biao;
b:array[1..100] of boolean;
t:array[0..100] of integer;
procedure init;
var
i,j:integer;
begin
assign(f1,'tianshu.in');reset(f1);
assign(F2,'tianshu.out');rewrite(f2);
readln(f1,n);
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),true);
a[1,1]:=1;
end;
function pd(x:integer):boolean;
var
i,j:Integer;
begin
pd:=true;
for i:=2 to trunc(sqrt(x)) do
if (x mod i)=0 then begin pd:=false;exit;end;
end;
procedure put(x:biao);
var
i,j:Integer;
begin
for i:=1 to n do
begin
for j:=1 to n do
write(f2,x[i,j],' ');
writeln(f2);
end;
close(f1);close(f2);
end;
procedure nb(x,y:integer);
var
i,j:Integer;
begin
for i:=2 to n*n do
if b[i] then
if ((x=1)and pd(i+a[x,y-1]))or ((y=1)and pd(i+a[x-1,y]))
or ((x<>1)and(y<>1)and pd(i+a[x,y-1])and pd(i+a[x-1,y])) then
begin
b[i]:=false;
a[x,y]:=i;
inc(y);
if y>n then begin inc(x);y:=1;end;
if x>n then begin inc(s);put(a);halt;end
else nb(x,y);
b[i]:=true;
dec(y);
if y=0 then begin dec(x);y:=n;end;
end;
end;
begin
init;
nb(1,2);
if (s=0)or (n=1) then write(f2,'NO');
close(f1);close(f2);
end.