从文件读入整数N(N〈=20)和N个[10,400]之间的自然数。
(1)求这N个数中合数组成的升序序列;
(2)求上述序列中每相邻两数的最大公约数中的质数序列。
例如:输入:9
63 13 77 143 57 28 56 45 30
输出:28 30 45 56 63 77 143
2 7 7 11
參考答案:const maxn=20;
var
fname:string;
a:array[1..maxn]of integer;
p:array[1..400]of boolean;
n:integer;
fin:text;
function gcd(a,b:integer):integer;
begin
if b=0 then gcd:=a else gcd:=gcd(b,a mod b);
end;
function ss(a:integer):boolean;
var i:integer;
begin
ss:=true;
for i:=1 to a do if a div i=0 then ss:=false;
end;
procedure sort;
var i,j,t:integer;
begin
for i:=1 to n-1 do
for j:=1 to n do
if a[i]<a[j] then begin
t:=a[i];a[i]:=a[j];a[j]:=t;
end;
for i:=1 to n do write(a[i],' ');
end;
procedure gcdp;
var i:integer;
k:array[1..maxn]of integer;
begin
for i:=1 to n-1 do k[i]:=gcd(a[i+1],a[i]);
for i:=1 to n-1 do if ss(k[i]) then write(k[i],' ');
end;
procedure init;
var i:integer;
begin
readln(fname);
assign(fin,fname);
reset(fin);
readln(n);
for i:=1 to n do read(a[i]);
close(fin);
end;
begin
init;
sort;
gcdp;
readln
end.