Pablo and The Secret Code

2.5

2 votes
Sorting, Strings, Easy-Medium
Problem

Pablo is trying to escape from the police master plan which Agent Murphy is trying to execute. While observing some things, he found that the police has a secret code for this plan. Pablo needs to obtain that code!

enter image description here

Pablo got an array of numbers A of length N

There can be many permutations (P1,P2....Pm) of that array.

For each permutation Pi, its code (an integer) is generated by concatenation of all the non-prime numbers in that permutation. Now, there will be many codes, as one code is generated for each permutation. But among those, there exists a secret code.

After some studying on the pattern, Gustavo finds out that the secret code is actually the largest one among all the codes!

Note :- There can be multiple occurrences of the secret code.

Can you help Pablo find the secret code?

INPUT

  • First line contains an integer T, the number of Test Cases.
  • Each test case consists of two lines.
  • The first line of each test case contains N, the number of integers in the array A. The second line of each test case contains space separated integers A1,A2..AN.

OUTPUT

  • Output should contain exactly T lines. Each line containing the secret code for that array. If no number inside the array is non-prime, print No Secret Code!

CONSTRAINTS

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 103
  • 0 ≤ Ai ≤ 105

DISTRIBUTION

  • 1 ≤ T ≤ 10 follows for each file.
  • 1 ≤ N ≤ 5
    0 ≤ Ai ≤ 100 - 10 Points
  • 1 ≤ N ≤ 100
    0 ≤ Ai ≤ 103 - 50 Points
  • 1 ≤ N ≤ 103
    0 ≤ Ai ≤ 105 - 100 Points
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Let us take the 2nd test case-

There are 3 numbers in the array A - 4, 7, 60

Since N is 3, 6 permutations are possible. Various permutations & their codes are -

P1 - [4,7,60] - 460
P2 - [4,60,7] - 460
P3 - [60,4,7] - 604
P4 - [60,7,4] - 604
P5 - [7,60,4] - 604
P6 - [7,4,60] - 460

Note that only numbers concatenated are non-primes [4,60] and 7 is not present in any of the codes.

Now, Among all these codes, since the secret code is maximum of all, the answer is 604

Editor Image

?