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++,
Clojure,
C#,
D,
Erlang,
F#,
Go,
Groovy,
Haskell,
Java,
Java 8,
JavaScript(Rhino),
JavaScript(Node.js),
Lisp,
Lisp (SBCL),
Lua,
Objective-C,
OCaml,
Octave,
Pascal,
Perl,
PHP,
Python,
Python 3,
R(RScript),
Racket,
Ruby,
Rust,
Scala,
Scala 2.11.8,
Swift,
Visual Basic

Initializing Code Editor...

OTHER PROBLEMS OF THIS CHALLENGE

{"68a48ec": "/pagelets/suggested-problems/algorithm/akash-and-polygons/", "68a4904": "/pagelets/problem-author-tester/algorithm/akash-and-polygons/", "68a48cc": "/pagelets/show-submission/algorithm/akash-and-polygons/", "68a4919": "/pagelets/problems-hint/algorithm/akash-and-polygons/", "68a492f": "/pagelets/recommended-problems/algorithm/akash-and-polygons/"}

{}

realtime.hackerearth.com

80

3f11613458d7604a63bbc936405337ac5c784398

58a29e5cae2309f04b28

/realtime/pusher/auth/