#B3750. Lucky Prime Numbers

    ID: 11409 Type: Default 1000ms 256MiB

Lucky Prime Numbers

Lucky Prime Numbers

A prime number is a positive integer greater than 1 that has no positive divisors other than 1 and itself. For example, 2, 3, 5, and 13 are prime, while 4, 9, 12, and 18 are not. Note that 1 is not considered a prime number.

A number is called a lucky prime if:

  • The number itself is prime.
  • If you repeatedly remove the least significant digit (i.e. take \(\lfloor n/10 \rfloor\)) the resulting number is still prime, until a one-digit prime is reached.

For example, consider \(233\):

  1. \(233\) is prime.
  2. \(23 = \lfloor233/10\rfloor\) is prime.
  3. \(2 = \lfloor23/10\rfloor\) is prime.

Thus, \(233\) is a lucky prime. On the other hand, \(211\) is not a lucky prime since \(21 = \lfloor211/10\rfloor\) is not prime.

Given two integers representing a range, your task is to find all lucky prime numbers within that range.

inputFormat

The input consists of two integers L and R (separated by spaces) representing the inclusive range in which you have to find lucky prime numbers. You can assume that \(2 \leq L \leq R \leq 10^6\).

outputFormat

Output all lucky prime numbers in the range \([L, R]\) in ascending order, separated by a space. If there are no lucky primes in the range, output -1.

sample

2 100
2 3 5 7 23 29 31 37 53 59 71 73 79