This page is still under construction.

Parts of this page are still being built. What you see may change.

Prime Suffixes

Time limit1sMemory limit512 MB

Summary
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 yy a suffix of a number xx if we can remove digits from the beginning of the decimal representation of xx to get yy. If the decimal representation of xx has no zeroes, none of the suffixes of xx has a leading zero. For example, the suffixes of 283283 are 283283, 8383, and 33.

An integer is prime if it has exactly two positive integer divisors. The number 11 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 aa and bb. Help Senya find how many integers between aa and bb he likes.

Input

The input contains two integers aa and bb (1≤a≤b≤10111 \le a \le b \le 10^{11}).

Output

Print the number of primes between aa and bb 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 55, 77, and 1313.

In the second example, every integer in the range has a 00 in its decimal representation.

In the third example, Senya likes the integer 283283, since 283283, 8383, and 33 are all prime.

Examples3

  1. Example 1

    Input
    4 13
    
    Expected output
    3
    
  2. Example 2

    Input
    101 109
    
    Expected output
    0
    
  3. Example 3

    Input
    281 286
    
    Expected output
    1