program MangSoHoanChinh;
const
MaxSize = 100;
type
Mang = array[1..MaxSize] of Integer;
procedure NhapMang(var arr: Mang; var n: Integer);
var
i: Integer;
begin
repeat
Write('Nhap so luong phan tu (5 <= n < 100): ');
Readln(n);
until (n >= 5) and (n < 100);
Writeln('Nhap mang ', n, ' phan tu:');
for i := 1 to n do
begin
Write('Phan tu ', i, ': ');
Readln(arr[i]);
end;
end;
function LaSoHoanChinh(num: Integer): Boolean;
var
i, tongUoc: Integer;
begin
if num <= 1 then
Exit(False);
tongUoc := 1;
for i := 2 to Trunc(Sqrt(num)) do
begin
if num mod i = 0 then
begin
tongUoc := tongUoc + i;
if i <> num div i then
tongUoc := tongUoc + num div i;
end;
end;
LaSoHoanChinh := t />end;
procedure InCacSoHoanChinh(arr: Mang; n: Integer);
var
i: Integer;
begin
Writeln('Cac so hoan chinh trong mang:');
for i := 1 to n do
begin
if LaSoHoanChinh(arr[i]) then
Write(arr[i], ' ');
end;
Writeln;
end;
function TinhTongSoHoanChinh(arr: Mang; n: Integer): Integer;
var
i: Integer;
begin
TinhTongSoHoanChinh := 0;
for i := 1 to n do
begin
if LaSoHoanChinh(arr[i]) then
TinhTongSoHoanChinh := TinhTongSoHoanChinh + arr[i];
end;
end;
function SoHoanChinhLonNhat(arr: Mang; n: Integer): Integer;
var
i, maxHoanChinh: Integer;
begin
maxHoanChinh := 0;
for i := 1 to n do
begin
if LaSoHoanChinh(arr[i]) and (arr[i] > maxHoanChinh) then
maxHoanChinh := arr[i];
end;
SoHoanChinhLonNhat := maxHoanChinh;
end;
var
mangSo: Mang;
kichThuoc, tong, maxHoanChinh: Integer;
begin
NhapMang(mangSo, kichThuoc);
InCacSoHoanChinh(mangSo, kichThuoc);
tong := TinhTongSoHoanChinh(mangSo, kichThuoc);
Writeln('Tong cac so hoan chinh trong mang la: ', tong);
maxHoanChinh := SoHoanChinhLonNhat(mangSo, kichThuoc);
Writeln('So hoan chinh lon nhat trong mang la: ', maxHoanChinh);
Readln;
end.