Cod sursa(job #158454)

Utilizator netedu_andreiFII Andrei Netedu netedu_andrei Data 13 martie 2008 17:33:02
Problema Ciurul lui Eratosthenes Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.69 kb
program ciur;   
var f,g:text;   
    i,j,n,k,s:longint;   
    a:array[1..2000000]of byte;   
begin  
assign(f,'ciur.in');reset(f);   
assign(g,'ciur.out');rewrite(g);   
readln(f,n);   
s:=0;   
for i:=2 to n do  
    if a[i]=0 then begin  
                   k:=i;   
                   s:=s+1;   
                   for j:=2 to n div k do a[j*k]:=1;   
  
                   end;   
writeln(g,s);   
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 i:=k to n do  
    if a[i]=0 then write(g,i,' ');   
close(f);   
close(g);   
end.