#P6523. 「Wdoi-1」加密通信

「Wdoi-1」加密通信

Background

After the Moon War, Yukari Yakumo set up a barrier in the Huai'an Passage, causing all information sent from the surface to the Lunar Capital to be intercepted and decrypted.

To maintain normal communication, Eirin Yagokoro and the moon rabbits developed a brand-new encryption method.

Problem Description

First, Eirin Yagokoro writes the plaintext AA to be encrypted. This plaintext consists of n1n - 1 positive integers.

Then, she constructs a ciphertext BB consisting of nn prime numbers, satisfying that for all i[1,n)\forall i \in [1,n), Bi×Bi+1=AiB_i \times B_{i + 1} = A_i.

To improve the efficiency of information usage, Eirin Yagokoro requires that the values of all primes appearing in BB must be within the range [1,M][1,M].

Input Format

The first line contains an integer TT, representing the number of plaintext groups to be encrypted.

For each group of plaintext:

The first line contains two integers n,Mn, M, representing (plaintext length +1+ 1), i.e., the length of the ciphertext to be found, and the maximum value of primes allowed to appear.

The next line contains n1n - 1 positive integers separated by spaces, representing the plaintext AA.

Output Format

For each group of plaintext, output one line:

  • If a solution exists, output any valid ciphertext BB. The nn primes in the ciphertext should be separated by spaces.

  • If no solution exists, output -1.

2
4 233
55 35 77
4 5
55 35 77 
11 5 7 11 
-1

Hint

Constraints

  • For 20%20\% of the testdata, n5n \le 5, M10M \le 10.

  • For 40%40\% of the testdata, Ai1012A_i \le 10^{12}.

  • For 70%70\% of the testdata, AiAi+1A_i \neq A_{i + 1}.

  • For 100%100\% of the testdata, 3n1053 \le n \le 10^5, 1Ai,M10181 \le A_i, M \le 10^{18}, 1T51 \le T \le 5.

  • The above subtasks are inclusive: 100%100\% includes 70%70\%, 70%70\% includes 40%40\%, \ldots\ldots, and so on.

Data Guarantee

  • If the condition that bib_i must be within [1,M][1,M] is ignored, there is guaranteed to be at least one valid solution.

  • There exists at least one pair (i,j)(i,j) such that AiAjA_i \neq A_j.

Additional Material

This material is not very relevant to solving the problem.

Baidu Baike - Prime Number

Translated by ChatGPT 5