program TimSoLonNhat;
var
N, i, j, count: integer;
isPrime: boolean;
function IsPrimeNumber(num: integer): boolean;
var
k: integer;
begin
if num < 2 then
begin
IsPrimeNumber := False;
Exit;
end;
for k := 2 to Trunc(Sqrt(num)) do
begin
if (num mod k) = 0 then
begin
IsPrimeNumber := False;
Exit;
end;
end;
IsPrimeNumber := True;
end;
begin
Write('Nhap gia tri N: ');
Readln(N);
for i := N - 1 downto 2 do
begin
count := 0;
isPrime := IsPrimeNumber(i);
if isPrime then
begin
for j := 2 to Trunc(Sqrt(i)) do
begin
if (i mod j) = 0 then
begin
count := count + 1;
end;
end;
if count = 1 then
begin
writeln('So lon nhat nho hon ', N, ' co duy nhat 2 uoc nguyen to la: ', i);
break;
end;
end;
end;
Readln;
end.