比赛 20140711B班小测 评测结果 AAAAAAAA
题目名称 等差数列 最终得分 100
用户昵称 传奇 运行时间 0.374 s
代码语言 Pascal 内存使用 3.35 MiB
提交时间 2014-07-11 15:12:25
显示代码纯文本
program uasco669;
var
  exist:array[-1001..125000]of boolean;
  base:array[0..40000]of longint;
  a:array[1..100000,1..2]of longint;
  len,i,j,tail,next,m,n,d,ans:longint;
  flag:boolean;

procedure init;
var
  i,j,m:longint;
begin
  readln(n);
  readln(m);
  ans:=0;
  fillchar(a,sizeof(a),0);
  fillchar(exist,sizeof(exist),false);
  fillchar(base,sizeof(base),0);
  for i:=0 to m do
  for j:=i to m do
   exist[sqr(i)+sqr(j)]:=true;
  for i:=(sqr(m) shl 1) downto 0 do
  if exist[i] then
  begin
    inc(base[0]);
	base[base[0]]:=i;
  end;
end;

procedure swap(var a,b:longint);
var
  t:longint;
begin
  t:=a; a:=b; b:=t;
end;

procedure qsort(l,r:longint);
var
  i,j,x,y:longint;
begin
  i:=l; j:=r;
  x:=a[(l+r)div 2,1];
  y:=a[(l+r)div 2,2];
  repeat
    while (a[i,2]<y)or((a[i,2]=y)and(a[i,1]<x)) do inc(i);
	while (a[j,2]>y)or((a[j,2]=y)and(a[j,1]>x)) do dec(j);
	if i<=j then
	begin
	  swap(a[i,1],a[j,1]);
	  swap(a[i,2],a[j,2]);
	  inc(i); dec(j);
	end;
  until i>j;
  if l<j then qsort(l,j);
  if i<r then qsort(i,r);
end;

begin
assign(input,'ariprog.in');reset(input);
assign(output,'ariprog.out');rewrite(output);

  init;
  for i:=1 to base[0]-1 do
  for j:=i+1 to base[0] do
  begin
    tail:=base[i]; d:=base[i]-base[j]; next:=base[j]; len:=1; flag:=true;
	if base[i]-(n-1)*d<0 then break;
	while (exist[next])and(flag) do
	begin
	  inc(len);
	  if len=n then
	  begin
	    flag:=false;
		inc(ans);
		a[ans,1]:=next;
		a[ans,2]:=d;
	  end;
	  dec(next,d);
	end;
  end;
  if ans=0 then
    writeln('NONE')
  else begin
    qsort(1,ans);
	for i:=1 to ans do
	 writeln(a[i,1],' ',a[i,2]);
  end;

close(input);close(output);
end.