Truncatable Primes

No attempts yetTime limit1sMemory limit512 MB

Problem

Recall that a prime is a positive integer with exactly two distinct divisors: 11 and itself. We say that a number aa is a prefix of a number bb if aa can be obtained by deleting some number of digits from the end of bb. For example, 12311231 is a prefix of 1231443312314433. A truncatable prime is a number all of whose prefixes of non-zero length are prime. For example, 2323 is a truncatable prime, because its non-empty prefixes 22 and 2323 are both prime.

Given two positive integers aa, bb (aba \le b), write a program that determines how many integers in the closed interval [a,b][a, b] are truncatable primes.

Input

A single line of standard input contains two integers aa, bb (1ab10181 \le a \le b \le 10^{18}), separated by a space.

Output

Print a single integer: the number of truncatable primes that are not less than aa and not greater than bb.

Hint

There are only finitely many such numbers. The first digit must be one of the single-digit primes 22, 33, 55, 77, and every time you append a digit on the right the resulting number must still be prime. So you can generate all such numbers in advance and then count those that fall inside the interval.