#P2459. Equal Cake Partition
Equal Cake Partition
Equal Cake Partition
Ghy has n underlings, including you, and he wants to distribute a rectangular cake equally among them. The cake is positioned in a 3D coordinate system with one vertex at the origin \(O=(0,0,0)\) and the opposite vertex at \((x,y,z)\), so that \(x\), \(y\), and \(z\) represent the length, width, and height respectively. Ghy intends to cut the cake into \(n\) congruent rectangular cuboids by making cuts parallel to the faces of the cake.
This is equivalent to finding three positive integers \(a\), \(b\), and \(c\) such that:
[ a \times b \times c = n, \quad a \mid x, \quad b \mid y, \quad c \mid z, ]
If such a triple exists, then each small cake will have dimensions \(\left(\dfrac{x}{a},\; \dfrac{y}{b},\; \dfrac{z}{c}\right)\). Otherwise, it is impossible to make the required partition.
Your task is to determine, for each test case, whether a valid partition exists. If it does, output the dimensions of one small cake; otherwise, output -1
.
inputFormat
The first line contains an integer \(T\) (the number of test cases). Each of the following \(T\) lines contains four space-separated integers \(n\), \(x\), \(y\), and \(z\), representing the number of underlings and the dimensions of the cake respectively.
outputFormat
For each test case, if a valid partition exists, output three space-separated integers representing the dimensions of one small cake (i.e. \(x/a\), \(y/b\), \(z/c\)). Otherwise, output -1
.
sample
1
1 2 3 4
2 3 4
</p>