P5316 Lianlian’s Math Problem.

Background

Lianlian is a cute girl, and recently she has been addicted to solving math problems.

Description

The problem Lianlian is working on now is very simple: there are $k \space (2\leq k\leq 4)$ numbers. Lianlian does not know what they are, but she knows the pairwise greatest common divisors and least common multiples of these numbers. As usual, Lianlian really wants to reconstruct those $k$ numbers, but now she needs to pretend she cannot do it, so she hands the problem to you. If you solve it successfully, Lianlian will cheer for you like crazy behind your back.

Input Format

The first line contains two integers $T$ and $k$. The next $2T$ lines contain $T$ test cases, and each test case consists of two lines. The first line contains $\frac{k(k-1)}2$ integers, representing the pairwise greatest common divisors of the $k$ unknown numbers, in arbitrary order. The second line contains $\frac{k(k-1)}2$ integers, representing the pairwise least common multiples of the $k$ unknown numbers, in arbitrary order.

Output Format

Output $T$ lines. Each line contains $k$ numbers separated by spaces, representing any one set of answers that matches the given data.

Explanation/Hint

It is guaranteed that for odd-numbered test points, the first line (the gcd line) is all $1$. |Test Point ID|$k$|Input Integers Do Not Exceed| |-|-|-| |1,2|2|$100$| |3,4|2|$1000$| |5,6|2|$10^7$| |7,8|3|$100$| |9,10|3|$10^7$| |11,12|3|$10^{14}$| |13,14|4|$100$| |15,16|4|$10^7$| |17,18|4|$10^{14}$| |19,20|4|$10^{18}$| It is guaranteed that the testdata has a solution, and $T\leq 5$. The SPJ scores according to the correct ratio within each test case, but if TLE, RE, etc. causes no output, you will get zero points. Translated by ChatGPT 5