SOLVE

LATER

Digits and Fun

Problem

Editorial

Analytics

Given a set of *N* digits, find the \(k^{th}\) smallest number that can be formed using them such that the sum of its digits is prime. If the answer does not exists or is greater than \(10^{18}\) print *1*.

**Input:**

First line consists of a single integer *T* denoting the number of test cases.

Second line consists of a single integer denoting *N*.

Third line consists of *N* space separated numbers denoting the set of digits.
Fourth line consists of a single integer denoting *k*.

**Output:**
Print the required answer in a new line for each test case.

**Constraints:**

\(1 \le N \le 9\)

\(1 \le k \le 10^{18}\)

Time Limit:
1.0 sec(s)
for each input file.

Memory Limit:
256 MB

Source Limit:
1024 KB

Marking Scheme:
Marks are awarded when all the testcases pass.

Allowed Languages:
C,
C++,
C++14,
Clojure,
C#,
D,
Erlang,
F#,
Go,
Groovy,
Haskell,
Java,
Java 8,
JavaScript(Rhino),
JavaScript(Node.js),
Julia,
Kotlin,
Lisp,
Lisp (SBCL),
Lua,
Objective-C,
OCaml,
Octave,
Pascal,
Perl,
PHP,
Python,
Python 3,
R(RScript),
Racket,
Ruby,
Rust,
Scala,
Swift,
Swift-4.1,
Visual Basic

Initializing Code Editor...

OTHER PROBLEMS OF THIS CHALLENGE

{"0d49dbb": "/pagelets/suggested-problems/algorithm/akash-and-polygons/", "3025857": "/pagelets/show-submission/algorithm/akash-and-polygons/", "0162e9f": "/pagelets/recommended-problems/algorithm/akash-and-polygons/", "434574c": "/pagelets/problem-author-tester/algorithm/akash-and-polygons/", "8fe82fe": "/pagelets/problems-hint/algorithm/akash-and-polygons/"}

realtime.hackerearth.com

80

3f11613458d7604a63bbc936405337ac5c784398

58a29e5cae2309f04b28

/realtime/pusher/auth/