Cod sursa(job #146816)
Utilizator | Data | 2 martie 2008 11:06:14 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 1.07 kb |
var n,i,s,j,m:longint;
v:array[1..2000000] of boolean;
p:array[1..10000] of longint;
f,g:text;
begin
assign(f,'ciur.in');
assign(g,'ciur.out');
reset(f);
rewrite(g);
readln(f,n);
for i:=1 to n do
v[i]:=true;
v[1]:=false;
s:=trunc(sqrt(n));
m:=0;
for i:=2 to s do
if v[i] then begin
j:=i+i;
while j<=n do begin
v[j]:=false;
j:=j+i
end;
end;
for i:=n downto 2 do
if v[i] then inc(m);
i:=n; j:=0;
while(i>=2)and(j<1000) do
begin
if v[i] then begin
inc(j);
p[j]:=i
end;
i:=i-1
end;
writeln(g,m);
if m>1000 then m:=1000;
for i:=m downto 1 do write(g,p[i],' ');
close(f);
close(g);
end.