Pagini recente » Cod sursa (job #603775) | Cod sursa (job #955652) | Cod sursa (job #1591112) | Cod sursa (job #1879155) | Cod sursa (job #304715)
Cod sursa(job #304715)
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;
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:integer);
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 b>=a 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 a>=b;
if a-ia>s 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
if (t[i]=1) and (i+p[k]<=max) then t[i+p[k]]:=1;
for j:=2 to n do
if t[x[j]]=0 then
begin
k:=k+1; p[k]:=x[k];
for i:=1 to max do
if (i mod p[k]=0) then t[i]:=1
else
if (t[i]=1) and (i+p[k]<max) then t[i+p[k]]:=1;
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.