Cod sursa(job #146180)

Utilizator borsosborsos adrian borsos Data 1 martie 2008 12:30:25
Problema Ciurul lui Eratosthenes Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.86 kb
var a:array[2..2000000] of boolean;
    i,j,n,k:longint;
    f,g:text;
begin
assign(f,'ciur.in'); reset(f);
assign(g,'ciur.out'); rewrite(g);
readln(f,n); close(f);
fillchar(a,sizeof(a),true);
k:=0;
for i := 2 to trunc(sqrt(n)) do
           if a[i] then begin
                   j:=2;
                   while i*j <=n do begin
                           a[i*j]:=false;
                           inc(j);
                                    end;
                        end;
for i := 2 to n do
      if a[i] then inc(k);
if k< 1000 then begin
           writeln(g,k);
           for i := 2 to n do
                if a[i] then write(g,i,' ');
                end else
                begin
           writeln(g,k);
           for i := 1000 downto 1 do
                 if a[n-1000+i] then write(g,n-1000+i,' ');
                end;
close(g);

end.