题意
找出范围[a,b](5 <= a < b <= 100,000,000)( 一亿)间的所有回文质数;
分析
找出所有的回文数再判断它们是不是质数(素数).
vara,b,l:longint;function work(w:longint):longint;vart,s:longint;begin t:=w; s:=0; while t<>0 do begin inc(s); t:=t div 10; end; work:=s;end;function ss(s:string):longint;varsz,i:longint;begin if (length(s)=2)and(s<>'11') then exit(0); val(s,sz); if (sz<a)or(sz>b) then exit(0); for i:=2 to trunc(sqrt(sz)) do if sz mod i=0 then begin exit(0); break; end; ss:=sz;end;procedure hw(k:longint);varw1,w2,i,j,bz:longint;s1,s2:string;begin if k>l then exit; if k mod 2=0 then begin w1:=1; w2:=9; for i:=1 to k div 2-1 do begin w1:=w1*10; w2:=w2*10+9; end; for i:=w1 to w2 do begin str(i,s1); s2:=s1; for j:=length(s1) downto 1 do s2:=s2+s1[j]; bz:=ss(s2); if bz<>0 then writeln(bz); end; end else begin w1:=1; w2:=9; for i:=1 to (k+1) div 2-1 do begin w1:=w1*10; w2:=w2*10+9; end; for i:=w1 to w2 do begin str(i,s1); s2:=s1; for j:=length(s1)-1 downto 1 do s2:=s2+s1[j]; bz:=ss(s2); if bz<>0 then writeln(bz); end; end; hw(k+1);end;begin read(a,b); l:=work(b); hw(1);end.
