#P1218. [USACO1.5] 特殊的质数肋骨 Superprime Rib

    ID: 218 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学递推USACO素数判断,质数,筛法

[USACO1.5] 特殊的质数肋骨 Superprime Rib

Description

Farmer John’s cows always produce the best ribs. You can recognize them by the numbers stamped on each rib by Farmer John and the USDA.

Farmer John is sure he sells genuine superprime ribs because, starting from the right and removing one rib at a time, the digits on the ribs that remain always form a prime number.

For example: for 7 3 3 17\ 3\ 3\ 1, the digits of all ribs 73317331 form a prime; with three ribs 733733 it is still prime; with two ribs 7373 it is prime; and, of course, the last rib 77 is also prime. 73317331 is called a superprime of length 44.

Write a program that, given the number of ribs nn, finds all superprimes of length nn. 11 is not a prime.

Input Format

A single line containing a positive integer nn.

Output Format

Output, in increasing order, all superprimes of length nn, one per line.

4

2333
2339
2393
2399
2939
3119
3137
3733
3739
3793
3797
5939
7193
7331
7333
7393

Hint

Constraints
For 100%100\% of the testdata, 1n81 \le n \le 8.

Problem translation from NOCOW.
USACO Training Section 1.5.

Translated by ChatGPT 5