my code stock.com

Snippet options

Download: Download snippet as 152-prime-palindromes.pas.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

{
ID:leaspos1
PROG:pprime
LANG:PASCAL
}
const
        up:array[1..9] of longint=(1,10,100,1000,10000,100000,1000000,10000000,100000000);
        down:array[1..9] of longint=(9,99,999,9999,99999,999999,9999999,99999999,999999999);
 
type
    int=longint;
 
var
   i,j,k,tt,l,r,w1,w2,len : int;
   t                      : string;
   p                      : char;
   
function check(x: int):boolean;
var
   i :int;
 
begin
   for i:=2 to trunc(sqrt(x)) do
      if x mod i=0 then exit(false);
   exit(true);
end; 
 
begin
   assign(input,'pprime.in');reset(input);
   assign(output,'pprime.out');rewrite(output);
   readln(l,r);
   w1:=trunc(ln(l)/ln(10))+1;w2:=trunc(ln(r)/ln(10))+1;
   if w1=1 then
   begin
      if l<=2 then writeln(2);
      if l<=3 then writeln(3);
      if l<=5 then writeln(5);
      if l<=7 then writeln(7);
      inc(w1);
   end;
   if l<=11 then writeln(11);
   for i:=w1 to w2 do
      if not odd(i) then continue
      else
      begin
         for j:=up[i>>1] to down[i>>1] do
         begin
            str(j,t);
            len:=length(t);
            t:=t+'$';
            for k:=len downto 1 do
               t:=t+t[k];
            for p:='0' to '9' do
            begin
               t[len+1]:=p;
               val(t,tt);
               if (tt<l) or (tt>r) then
               begin
                  if tt>r then break
                  else
                     continue;
               end
               else
                  if check(tt) then
                     writeln(t);
            end;
         end;
      end;
   close(input);close(output);
end.

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.