Pagini recente » jc2016/clasament | Cod sursa (job #2271745) | Cod sursa (job #1176226) | Cod sursa (job #2666469) | Cod sursa (job #146192)
Cod sursa(job #146192)
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);
k:=0;
for i := n downto 1 do begin
if a[i] then inc(k);
if k=1000 then break;
end;
for k:= i-1 to n do
if a[k] then write(g,k,' ');
end;
close(g);
end.