#P1218. Special Prime Ribs

    ID: 14283 Type: Default 1000ms 256MiB

Special Prime Ribs

Special Prime Ribs

Farmer John's cows produce the best ribs, and each rib is tagged with a digit by Farmer John and the U.S. Department of Agriculture. A rib sequence is called a special prime if the number formed by all its digits is prime, and if by successively removing the rightmost digit the remaining number is still prime. For example, consider the rib digits 7 3 3 1:
- The full number is \(7331\), which is prime.
- Removing the rightmost digit gives \(733\), which is prime.
- Removing the rightmost digit again gives \(73\), prime.
- Finally, \(7\) is also prime.

This qualifies 7331 as a special prime of length 4. Note that 1 is not considered a prime.

Given a number n representing the number of ribs (or digits), your task is to find all the n-digit special primes. The output should list these numbers in ascending order, one per line.

inputFormat

The input consists of a single integer n (where n ≥ 1), which represents the number of digits in the rib sequence.

outputFormat

Output all the special primes with exactly n digits in ascending order. Each number should be printed on a new line.

sample

1
2

3 5 7

</p>