Ten Ranges
Time limit2sMemory limit512 MB
Count the integers in each range [l, r] (r up to 10^18) that have no prime as a decimal subsequence, for up to 10 queries.
- Level
Medium7 of 10
- Topics
- Dynamic programming, String matching, Number theory
- Solved
- No attempts yet
Problem
An integer is a decimal subsequence of an integer if the decimal representation of can be obtained from that of by erasing some digits. Erasing no digits is allowed, but not all of them.
An integer is prime if and its only positive divisors are 1 and .
An integer is secondary if no integer that is prime is a decimal subsequence of . For example, 168 is secondary because none of 1, 6, 8, 16, 18, 68, and 168 is prime, while 169 is not secondary because 19 is prime.
Find the number of secondary integers in each range .
Input
The first line contains a single integer (), the number of ranges.
Each of the following lines contains two integers and (), the boundaries of one range.
Output
Print the number of secondary integers in each given range, in the order of input.
Hint
In the example test case, the secondary integers in are 8, 9, 10, 14, and 16. The secondary integers in are 160, 164, 166, and 168.