brvn-bai2 22-23

15/12/2022

to hai2k9

Code
program bai2;
uses crt;
var n : longint;
    i,j,idx : longint;
    a, res : array[1..1000000] of longint;

function isprime(x : longint) : boolean;
var ii : longint;
begin
    if x < 2 then exit(false);
    for ii := 2 to round(sqrt(x)) do
      if x mod ii = 0 then exit(false);
    exit(true);
end;

procedure sort;
var tam : longint;
begin
    for i := 1 to idx-1 do
      for j := i+1 to idx do
        if (res[i] > res[j]) then
          begin
              tam := res[i];
              res[i] := res[j];
              res[j] := tam;
          end;
end;


BEGIN
    clrscr;
    readln(n);
    for i := 1 to n do
      read(a[i]);
    idx := 1;
    for i := 1 to n do
      if (isprime(a[i])) then
        begin
            res[idx] := a[i];
            idx := idx+1;
        end;
    idx:= idx-1;
    sort;
    for i := 1 to idx do
     write(res[i],' ');
    readln;

END.