记录编号 |
110437 |
评测结果 |
AAAAAAAA |
题目名称 |
等差数列 |
最终得分 |
100 |
用户昵称 |
筽邝 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.407 s |
提交时间 |
2014-07-11 16:45:42 |
内存使用 |
0.51 MiB |
显示代码纯文本
program cojs669;
type
node=record
a,b:longint;
end;
var
f:array[0..125000]of boolean;
base:array[0..40000]of longint;
ans:array[0..10000]of node;
i,n,d,j,next,count,len:longint;
procedure init;
var
i,j,m:longint;
begin
readln(n);
readln(m);
for i:=0 to m do
for j:=i to m do
f[sqr(i)+sqr(j)]:=true;
for i:=0 to sqr(m)*2 do
if f[i] then
begin
inc(base[0]);
base[base[0]]:=i;
end;
end;
procedure qsort(l,r:longint);
var
i,j:longint;
x,t:node;
begin
i:=l; j:=r;
x:=ans[(l+r) div 2];
repeat
while (ans[i].b<x.b)or((ans[i].b=x.b)and(ans[i].a<x.a)) do inc(i);
while (ans[j].b>x.b)or((ans[j].b=x.b)and(ans[j].a>x.a)) do dec(j);
if i<=j then
begin
t:=ans[i]; ans[i]:=ans[j]; ans[j]:=t;
inc(i); dec(j);
end;
until i>j;
if i<r then qsort(i,r);
if l<j then qsort(l,j);
end;
begin
assign(input,'ariprog.in');reset(input);
assign(output,'ariprog.out');rewrite(output);
init;
len:=0;
i:=0;
while i<base[0] do
begin
inc(i);
for j:=i+1 to base[0] do
begin
d:=base[j]-base[i];
if base[i]+(n-1)*d>base[base[0]] then break;
count:=1;
next:=base[i]+d;
while f[next] do
begin
inc(count);
if count=n then break;
inc(next,d);
end;
if count=n then
begin
inc(len);
ans[len].a:=base[i]; ans[len].b:=d;
end;
end;
end;
if len=0 then
begin
writeln('NONE');
close(input);close(output);
halt;
end;
qsort(1,len);
for i:=1 to len do
writeln(ans[i].a,' ',ans[i].b);
close(input);close(output);
end.