program PrimePalindromes; uses crt; var infile,outfile:text; x, y:longint; L, U, start, numpp: longint; prime: array[2..1000000] of boolean; function ispalin(num:longint): boolean; var nums:string; x, l:integer; palin:boolean; begin str(num,nums); palin:=true; l:=length(nums); case l of 1: palin:=true; 2: begin if nums[1]<>nums[2] then palin:=false; end; else begin for x:= 1 to l div 2 do if nums[x] <> nums[l-x+1] then palin:=false; end; end; ispalin:=palin; end; begin for x:=2 to 1000000 do prime[x]:=true; start:=2; while start <= 500000 do begin for x:=2 to 1000000 div start do prime[start*x]:=false; repeat inc(start); until prime[start]; end; assign(infile,'DATA51.txt'); reset(infile); assign(outfile,'OUT51.txt'); rewrite(outfile); for x:=1 to 5 do begin readln(infile,L,U); numpp:=0; for y:= L to U do begin if ispalin(y) then begin if prime[y] then inc(numpp); end; end; writeln(outfile,numpp); end; close(infile); close(outfile); end.