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,
Visual Basic

Initializing Code Editor...

OTHER PROBLEMS OF THIS CHALLENGE

{"933fc4e": "/pagelets/problems-hint/algorithm/akash-and-polygons/", "c2b5d4d": "/pagelets/recommended-problems/algorithm/akash-and-polygons/", "fa8ac13": "/pagelets/problem-author-tester/algorithm/akash-and-polygons/", "d3e7b59": "/pagelets/suggested-problems/algorithm/akash-and-polygons/", "6834c59": "/pagelets/show-submission/algorithm/akash-and-polygons/"}

realtime.hackerearth.com

80

3f11613458d7604a63bbc936405337ac5c784398

58a29e5cae2309f04b28

/realtime/pusher/auth/