#P7588. 双重素数(2021 CoE-II A)
双重素数(2021 CoE-II A)
Description
A prime number is a natural number greater than that has no divisors other than and itself. A double prime is defined as a prime number whose sum of digits is also a prime number. Given a closed interval, determine how many double primes are in this interval.
Input Format
The input contains multiple sets of testdata.
The first line contains an integer , representing the number of test cases. Each of the next lines contains one test case, with two integers and separated by a space.
Output Format
For each test case, output one line containing an integer, representing the number of double primes in the closed interval .
4
3 3
4 4
1 5
1 15
1
0
3
5
Hint
Sample explanation.
From to , there are prime numbers: , , , , , . For the first five primes, the sum of digits is also prime, so they are all double primes. The sum of digits of the prime is , which is not prime, so is not a double prime.
Constraints.
- Subtask : , points.
- Subtask : , points.
- Subtask : , points.
- Subtask : , points.
For of the data, .
Hint (the data has been strengthened).
The last subtask requires your program to have high space efficiency and time efficiency, otherwise it is easy to exceed the memory limit or time limit.
Translated by ChatGPT 5
京公网安备 11011102002149号