pascal回文数问题19
发布网友
发布时间:2023-09-22 17:30
我来回答
共1个回答
热心网友
时间:2024-11-23 11:57
program ex12b(input,output);
var a,b,j,k,l,n:longint;
sth:string;
l1,l2,i,d1,d2:integer;
function power(c,d:integer):longint;
var m:integer;
begin
power:=1;
for m:=1 to d do begin power:=power*c; end;
end;
begin
assign(input,'pprime.in');
assign(output,'pprime.out');
reset(input);
rewrite(output);
read(a,b);
str(a,sth);
l1:=length(sth);
str(b,sth);
l2:=length(sth);
for i:=l1 to l2 do
begin
if odd(i) then d1:=(i div 2)+1 else d1:=(i div 2);
if odd(i) then d2:=d1-1 else d2:=d1;
for j:=power(10,d1-1) to power(10,d1)-1 do
begin
n:=j;
str(j,sth);
for k:=d2 downto 1 do n:=n*10+ord(sth[k])-48;
if (n>=a) and (n<=b) then
for l:=2 to trunc(sqrt(n)) do
if (n mod l)=0 then break
else if l=trunc(sqrt(n))
then writeln(n);
end;
end;
close(input);
close(output);
end.