Cod sursa(job #149984)

Utilizator andrici_cezarAndrici Cezar andrici_cezar Data 6 martie 2008 13:58:30
Problema Ciurul lui Eratosthenes Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.92 kb
program p21;
var f,g:text;
    a:array[1..2000000]of byte;
    n,q,j,k,i,x:longint;
begin
assign(f,'ciur.in');reset(f);
assign(g,'ciur.out');rewrite(g);
readln(f,n);
a[1]:=1;
for i:=1 to n do
    if a[i]=0 then for j:=i+1 to n do
                   begin
                         if j mod i =0 then begin
                                            a[j]:=1;
                                            x:=1;
                                            end;
                  end;
for i:=n downto 1000 do
    if a[i]=0 then begin
                    k:=k+1;
                    break;
                    end;
for j:=1 to n do
   if a[j]=0 then q:=q+1;

if k>0 then for j:=1000 downto n do
            begin
            writeln(g,k);
            if a[i]=0 then write(g,i,' ');
            end
else begin
     writeln(g,q);
     for j:=1 to n do
         if a[j]=0 then write(g,j,' ');
     end;
close(g);
end.