比赛 20121109 评测结果 AAWWAWWWWAWAAAW
题目名称 喜欢摇头的数学牛 最终得分 46
用户昵称 FoolMike 运行时间 3.731 s
代码语言 Pascal 内存使用 11.61 MiB
提交时间 2014-09-13 23:20:40
显示代码纯文本
var
b,c,g,n,m,k,j:longint;
a:array[0..3000000]of longint;
ans:array[1..201]of longint;

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

begin
assign(input,'tinkle.in');
reset(input);
assign(output,'tinkle.out');
rewrite(output);
read(k,j);
g:=0;

for b:=2 to 2000000 do
if a[b]=0 then
  begin
  if g<>-1 then inc(g);
  if g=k then
    begin
    k:=b;
    g:=-1;
    end;
  for c:=2 to 2000000 div b do a[c*b]:=1;
  end;
a[1]:=1;

b:=k;c:=k;g:=0;
repeat
inc(b);
if c>1 then dec(c);
if a[b]=0 then
  begin
  inc(g);
  ans[g]:=b;
  end;
if a[c]=0 then
  begin
  inc(g);
  ans[g]:=c;
  end;
until 2*j<=g;

kuaipai(1,g);
for j:=1 to 2*j do
write(ans[j],' ');
writeln;
close(input);close(output);
end.