Pagini recente » Cod sursa (job #193953) | Cod sursa (job #81692) | Cod sursa (job #374258) | Cod sursa (job #2948533) | Cod sursa (job #304763)
Cod sursa(job #304763)
program pascal;
var f,g:text; t:array[1..50000] of byte; x,p:array[1..1000] of longint;
max,i,k,j,n,aux:longint; c:int64;
procedure citire;
begin
assign(f,'economie.in'); reset(f);
assign(g,'economie.out'); rewrite(g);
readln(f,n);
max:=0;
for i:=1 to n do
begin
readln(f,x[i]);
if x[i]>max then max:=x[i];
end;
close(f);
end;
procedure sort(l,r:longint);
var i,j,pivot:longint;
begin
i:=1; j:=r; pivot:=x[random(r-1)+1];
repeat
while x[i]<pivot do i:=i+1;
while pivot<x[j] do j:=j-1;
if i<=j then
begin
aux:=x[i];
x[i]:=x[j];
x[j]:=aux;
i:=i+1; j:=j-1;
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
procedure sorte;
begin
k:=1; p[k]:=x[1];
for i:=1 to max do
if (i mod p[k]=0) then t[i]:=1
else
begin
c:=i+p[k];
if (t[i]=1) and (c<=max) then t[i+p[k]]:=1;
end;
for j:=2 to n do
if t[x[j]]=0 then
begin
k:=k+1; p[k]:=x[j];
for i:=1 to max do
if (i mod p[k]=0) then t[i]:=1
else
begin
c:=i+p[k];
if (t[i]=1) and (c<=max) then t[c]:=1;
end;
end;
end;
procedure afisare;
begin
writeln(g,k);
for i:=1 to k do writeln(g,p[i]);
close(g);
end;
begin
citire;
sort(1,n);
sorte;
afisare;
end.