Pagini recente » Cod sursa (job #2608064) | Cod sursa (job #1502166) | Cod sursa (job #2796743) | Cod sursa (job #2206871) | Cod sursa (job #304725)
Cod sursa(job #304725)
program pascal;
var f,g:text; t:array[1..50000] of byte; x,p:array[1..1000] of longint;
max,i,k,j,n: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 quick(s,d:longint);
var a,ia,aux,b:longint;
begin
a:=s; b:=d;
repeat
while x[a]<x[b] do b:=b-1;
aux:=x[a]; x[a]:=x[b]; x[b]:=aux; ia:=1; a:=a+1;
if a<b then
begin
while x[a]<x[b] do a:=a+1;
if a<>b then
begin
aux:=x[a]; x[a]:=x[b]; x[b]:=aux; ia:=0; b:=b-1;
end;
end;
until b<=a;
if s<a-ia then quick(s,a-ia);
if a-ia+1<d then quick(a-ia+1,d);
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;
quick(1,n);
sorte;
afisare;
end.