Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

做到哭死了.....走过路过,千万不要错过帮我看看.....

Posted by xiaobai1 at 2008-02-02 23:07:04 on Problem 1595
const
  q=1500;

var
  a,b:array [0..2000] of longint;
  n,m:longint;

procedure init;
  var
    i,j,k,l:longint;
  begin
    fillchar(a,sizeof(a),0);
    fillchar(b,sizeof(b),0);
    for i:=1 to q do a[i]:=i;
    for i:=2 to q div 2 do
      for j:=2 to q div i do a[i*j]:=0;
    for i:=1 to q do
      if a[i]<>0 then b[i]:=i;
    for i:=1 to q do
      if a[i]=0 then
        begin
          j:=i+1;
          while (j<q) and (a[j]=0) do inc(j);
          if a[j]<>0 then
            begin a[i]:=a[j];a[j]:=0;b[j]:=i;end;
        end;
  end;

procedure main;
  var
    i,j,k,l,x,y:longint;
  begin
    while not eof do
      begin
        readln(n,m);write(n,' ',m,':');x:=0;y:=0;
        if b[n]<>0 then l:=b[n] else
          begin
            j:=n-1;
            while (j>1) and (b[j]=0) do dec(j);
            if b[j]<>0 then l:=b[j];
          end;
        if 2*m>=l then
          begin
            for i:=1 to l do write(' ',a[i]);
            writeln;writeln;
          end
        else
          begin
            if l mod 2=0 then
              begin
                k:=2*m;
                x:=l div 2-k div 2+1;
                y:=l div 2+k div 2;
              end
            else
              begin
                x:=l div 2;
                y:=(l+1) div 2+1;
              end;
            for i:=x to y do write(' ',a[i]);
            writeln;writeln;
          end;
      end;
  end;

begin
  assign(input,'a1595.in');
  reset(input);
  init;
  main;
  close(input);
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator