Вот жутко неэффективное решение, для нормального надо писать решето эратосфена, можно нагуглить, если нужна эффективность
function isPrime (a : integer) : boolean; var i, lim : integer; begin if n < 4 then begin if n = 1 then isPrime := false else isPrime := true; exit; end; lim := trunc (sqrt (a)); for i := 2 to lim do if a mod i = 0 then begin isPrime := false; exit; end; isPrime := true; end;
var a : array of array of integer; b : array of integer; i, j, n : integer;
begin read (n); setlength (a, n, n); setlength (b, n); for i := 0 to n - 1 do for j := 0 to n - 1 do read (a[i, j]); for i := 0 to n - 1 do begin b[i] := 0; for j := 0 to n - 1 do if isPrime(a[i, j]) then inc (b[i]); end; for i := 0 to n - 1 do begin if b[i] <= 2 then for j := 0 to n - 1 do write (a[i, j], ' ') else for j := 0 to n - 1 do write ('0 '); writeln; end; end.
function isPrime (a : integer) : boolean;
var
i, lim : integer;
begin
if n < 4 then begin
if n = 1 then isPrime := false else isPrime := true;
exit;
end;
lim := trunc (sqrt (a));
for i := 2 to lim do
if a mod i = 0 then
begin
isPrime := false;
exit;
end;
isPrime := true;
end;
var
a : array of array of integer;
b : array of integer;
i, j, n : integer;
begin
read (n);
setlength (a, n, n);
setlength (b, n);
for i := 0 to n - 1 do
for j := 0 to n - 1 do
read (a[i, j]);
for i := 0 to n - 1 do
begin
b[i] := 0;
for j := 0 to n - 1 do
if isPrime(a[i, j]) then inc (b[i]);
end;
for i := 0 to n - 1 do
begin
if b[i] <= 2 then
for j := 0 to n - 1 do
write (a[i, j], ' ')
else
for j := 0 to n - 1 do write ('0 ');
writeln;
end;
end.