program MangSoNguyenTo;
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 (n < 100): ');
Readln(n);
until 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 LaSoNguyenTo(num: Integer): Boolean;
var
i: Integer;
begin
LaSoNguyenTo := True;
if num < 2 then
Exit(False);
for i := 2 to Trunc(Sqrt(num)) do
begin
if num mod i = 0 then
begin
LaSoNguyenTo := False;
Exit;
end;
end;
end;
procedure InCacSoNguyenTo(arr: Mang; n: Integer);
var
i: Integer;
begin
Writeln('Cac so nguyen to trong mang:');
for i := 1 to n do
begin
if LaSoNguyenTo(arr[i]) then
Write(arr[i], ' ');
end;
Writeln;
end;
function TinhTongSoNguyenTo(arr: Mang; n: Integer): Integer;
var
i: Integer;
begin
TinhTongSoNguyenTo := 0;
for i := 1 to n do
begin
if LaSoNguyenTo(arr[i]) then
TinhTongSoNguyenTo := TinhTongSoNguyenTo + arr[i];
end;
end;
function SoNguyenToNhoNhat(arr: Mang; n: Integer): Integer;
var
i, minNguyenTo: Integer;
begin
minNguyenTo := MaxInt;
for i := 1 to n do
begin
if LaSoNguyenTo(arr[i]) and (arr[i] < minNguyenTo) then
minNguyenTo := arr[i];
end;
SoNguyenToNhoNhat := minNguyenTo;
end;
procedure InCacSoNguyenToLienTiepNhoHonN(arr: Mang; n: Integer);
var
i, j: Integer;
begin
Writeln('Cac so nguyen to lien tiep nho hon ', n, ':');
for i := 1 to n - 1 do
begin
for j := i + 1 to n do
begin
if LaSoNguyenTo(arr[i]) and LaSoNguyenTo(arr[j]) and (arr[i] < n) and (arr[j] < n) then
Write('(', arr[i], ', ', arr[j], ') ');
end;
end;
Writeln;
end;
var
mangSo: Mang;
kichThuoc, tong, minNguyenTo: Integer;
begin
NhapMang(mangSo, kichThuoc);
InCacSoNguyenTo(mangSo, kichThuoc);
tong := TinhTongSoNguyenTo(mangSo, kichThuoc);
Writeln('Tong cac so nguyen to trong mang la: ', tong);
minNguyenTo := SoNguyenToNhoNhat(mangSo, kichThuoc);
Writeln('So nguyen to nho nhat trong mang la: ', minNguyenTo);
InCacSoNguyenToLienTiepNhoHonN(mangSo, kichThuoc);
Readln;
end.