問題一覧 > 通常問題

No.775 tatyam and Prime Daifugo (hard)

レベル : / AI推定難易度 : 2550 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 3
作問者 : tatyam / テスター : Shuz*
お気に入りにしたユーザー ProblemId : 2470 / 自分の提出
問題文最終更新日: 2020-05-02 16:55:10
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2018 (順位表) の他の問題:

Notice

This problem is a truly terrible problem, so if possible we would like you to enjoy the other problems first, and therefore, once you have solved the other problems and have free time, and moreover that free time

Problem Statement

tatyam is playing Prime Daifugo with extended rules.
In this version of Prime Daifugo, cards with numbers from 1 to 99 written on them are used, and you can play the numbers in your hand by concatenating them if the result is a prime.
tatyam has started wanting to look for the largest prime obtainable by rearranging.
Among the numbers tatyam can make using all the cards in the hand, output $K$ of them in descending order, starting from the largest.

Input

$N\ K$
$a_1$ $a_2$ $\cdots$ $a_N$

$1≤N≤100$
$1≤K≤1000$
$1≤a_i≤99$
There are at least $K$ distinct numbers that can be made by rearranging.

Output

Among the numbers that can be made by rearranging $a_i$, output $K$ of them in descending order, starting from the largest, separated by newlines.

Sample

Sample 1
Input
1 1
2
Output
2

Sample 2
Input
5 5
2 4 6 8 11
Output
864211
864112
862411
862114
861142

Sample 3
Input
5 3
1 7 7 9 13
Output
977131
977113
971713

Sample 4
Input
10 10
99 98 96 94 92 90 88 86 85 82
Output
99989694929088868582
99989694929088868285
99989694929088858682
99989694929088858286
99989694929088828685
99989694929088828586
99989694929086888582
99989694929086888285
99989694929086858882
99989694929086858288

Sample 5
Input
36 3
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 77 6 5
Output
777777777777777777777777777777777777777777777777777765
777777777777777777777777777777777777777777777777777756
777777777777777777777777777777777777777777777777777675

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。