Pascal
Modified: Wednesday, 22-12-2021 07:00 AM
Để bảo vệ máy tính của mình, Lan đã đặt mật khẩu là 1 số nguyên tố.
Để có thể lấy lại mật khẩu, Lan đã lưu mật khẩu vào 1 tệp có dưới 1000 kí tự.
Trong đó số nguyên tố lớn nhất trong tệp chính là mật khẩu cần tìm của Lan
var s:string;
Pass:longint;
i:byte;
function snt(x:longint):boolean;
var i:longint;
begin
if x<2 then exit(false)
else
for i:=2 to round(sqrt(x)) do
if x mod i=0 then exit(false);
exit(true);
end;
procedure check(s:string);
var i,j:byte;
ss:string;
n:longint;
begin
for i:=length(s) downto 1 do
for j:=1 to (length(s)-i+1) do
begin
ss:=copy(s,j,i);
val(ss,n);
if snt(n) then
begin
if (n>pass) then pass:=n;
break;
end;
end;
end;
procedure tachso(s:string);
begin
ss:='';
pass:=0;
for i:=1 to (length(s)+1) do
begin
if s[i] in ['0'..'9'] then ss:=ss+s[i]
else
begin
if ss<>'' then
check(ss);
ss:='';
end;
end;
end;
begin
s:='test#1234.pass12'; //Doc chuoi tu File
TachSo(s);
write(pass);
readln;
end.