Cod sursa(job #150172)

Utilizator andrici_cezarAndrici Cezar andrici_cezar Data 6 martie 2008 17:44:11
Problema Ciurul lui Eratosthenes Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.76 kb
program p21;
var f,g:text;
    a:array[1..2000000]of byte;
    n,q,j,k,i: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 begin
                   begin
		   k:=i;
                   q:=q+1;
                   for j:=2 to n div k do a[j*k]:=1;                                                                                                           
                   end;
     writeln(g,q);
j:=0;
for i:=n downto 2 do 
	if a[i]=0 then begin
	               k:=i;
                       j:=j+1;
                       if j=1000 then break; 
                       end;
     for j:=k to n do
         if a[j]=0 then write(g,j,' ');
     end;
close(g);
end.