
Для чисел от A до B найти количество "зеркально простых" чисел.
Код решения:
*****
var t:string;
c:char;
code:word;
a, b, rez, i, mm, j, ti, temp:longint;
flag:boolean;
function proste(t:longint):boolean;
var s, i, k, j:longint;
begin
proste:=false;
if t=1 then proste:=false else
if t=2 then proste:=true
else begin
k:=0;
for i:=2 to trunc(sqrt(t)) do
if t mod i = 0 then k:=k+1;
if k=0 then proste:=true;
end;
end;
BEGIN
readln (a, b);
if a>b then begin i:=a; a:=b; b:=i; end;
rez:=0;
for i:=a to b do
begin
if proste(i) then
begin
t:=''; temp:=i;
while temp>0 do
begin
t:=t+chr((temp mod 10) +48);
temp:=temp div 10;
end;
val(t, ti, code);
if proste(ti) then inc (rez);
end;
end;
writeln (rez);
END.
c:char;
code:word;
a, b, rez, i, mm, j, ti, temp:longint;
flag:boolean;
function proste(t:longint):boolean;
var s, i, k, j:longint;
begin
proste:=false;
if t=1 then proste:=false else
if t=2 then proste:=true
else begin
k:=0;
for i:=2 to trunc(sqrt(t)) do
if t mod i = 0 then k:=k+1;
if k=0 then proste:=true;
end;
end;
BEGIN
readln (a, b);
if a>b then begin i:=a; a:=b; b:=i; end;
rez:=0;
for i:=a to b do
begin
if proste(i) then
begin
t:=''; temp:=i;
while temp>0 do
begin
t:=t+chr((temp mod 10) +48);
temp:=temp div 10;
end;
val(t, ti, code);
if proste(ti) then inc (rez);
end;
end;
writeln (rez);
END.
*****
Комментариев нет:
Отправить комментарий