Prime Suffixes
Time limit1sMemory limit512 MB
Count numbers in [a, b] whose decimal digits contain no zero and whose every suffix is prime.
- Level
Medium7 of 10
- Topics
- Number theory, Brute force, Recursion, Math
- Solved
- No attempts yet
Statement
We call a number a suffix of a number if we can remove digits from the beginning of the decimal representation of to get . If the decimal representation of has no zeroes, none of the suffixes of has a leading zero. For example, the suffixes of are , , and .
An integer is prime if it has exactly two positive integer divisors. The number is not prime: it has only one positive integer divisor.
Senya likes prime numbers that have no zeroes in their decimal representation and whose every suffix is also prime.
You are given integers and . Help Senya find how many integers between and he likes.
Input
The input contains two integers and ().
Output
Print the number of primes between and inclusive such that they have no zeroes in their decimal representation, and if any number of their leading digits are removed, the resulting number is still prime.
Notes
In the first example, Senya likes the integers , , and .
In the second example, every integer in the range has a in its decimal representation.
In the third example, Senya likes the integer , since , , and are all prime.