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,
Lisp,
Lisp (SBCL),
Lua,
Objective-C,
OCaml,
Octave,
Pascal,
Perl,
PHP,
Python,
Python 3,
R(RScript),
Racket,
Ruby,
Rust,
Scala,
Swift,
Visual Basic,
Kotlin

Initializing Code Editor...

OTHER PROBLEMS OF THIS CHALLENGE

{"ee560b1": "/pagelets/problems-hint/algorithm/akash-and-polygons/", "ee5605b": "/pagelets/show-submission/algorithm/akash-and-polygons/", "ee560c7": "/pagelets/recommended-problems/algorithm/akash-and-polygons/", "ee5609c": "/pagelets/problem-author-tester/algorithm/akash-and-polygons/", "ee56085": "/pagelets/suggested-problems/algorithm/akash-and-polygons/"}

{}

realtime.hackerearth.com

80

3f11613458d7604a63bbc936405337ac5c784398

58a29e5cae2309f04b28

/realtime/pusher/auth/