Palindromic Prime

1

1 votes
Data Structures, 1-D, Arrays
Problem

Given two numbers L and R. Find the count of number N in range [L,R] such that N satisfies given conditions :-

1. N is a prime number. 2. N is a palindromic number. For ex : N = 3 is a valid but N = 23 is not valid as it is not palindromic.

Example

If L = 150 and R = 200. There are 3 such numbers which satisfy the given conditions.

  • 151, 181, 191 are 3 such numbers which are prime as well as palindromic.

Function Description

Complete the palPrime function provided in the editor. This function takes the following 2 parameters and returns the required answer.

  • L : Represents the starting of range
  • R : Represents the end of range

Input First line contain T, number of test cases Next T line contain two space separated integers L R. Output For each test case, output count of valid N possible in given range.

Constrains 1T105 1LR105

Sample Input
3
1 9
9 11
3 7
Sample Output
4
1
3
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

2, 3, 5, 7, 11 are first few palindromic prime numbers

Contributers:
Editor Image

?