VK Cup 2012 Round 2
D
Large Refrigerator
Codeforces
2900
原题
← CE →
翻译中…

Vasya wants to buy a new refrigerator. He believes that a refrigerator should be a rectangular parallelepiped with integer edge lengths. Vasya calculated that for daily use he will need a refrigerator with volume of at least $*V*$. Moreover, Vasya is a minimalist by nature, so the volume should be no more than $*V*$, either — why take up extra space in the apartment? Having made up his mind about the volume of the refrigerator, Vasya faced a new challenge — for a fixed volume of $*V*$ the refrigerator must have the minimum surface area so that it is easier to clean.

翻译中…

The volume and the surface area of a refrigerator with edges $*a*$, $*b*$, $*c*$ are equal to $*V* = *abc*$ and $*S* = 2(*ab* + *bc* + *ca*)$, correspondingly.

翻译中…

Given the volume $*V*$, help Vasya find the integer lengths for the refrigerator's edges $*a*$, $*b*$, $*c*$ so that the refrigerator's volume equals $*V*$ and its surface area $*S*$ is minimized.

翻译中…

Input

翻译中…

The first line contains a single integer $*t*$ ($1 ≤ *t* ≤ 500$) — the number of data sets.

翻译中…

The description of $*t*$ data sets follows. Each set consists of a single integer $*V*$ ($2 ≤ *V* ≤ 10^{18}$), given by its factorization as follows.

翻译中…

Let $*V*$ = $*p*_{1}^{*a*_{1}}*p*_{2}^{*a*_{2}}... *p*_{*k*}^{*a*_{*k*}}$, where $*p*_{*i*}$ are different prime numbers and $*a*_{*i*}$ are positive integer powers.

翻译中…

Then the first line describing a data set contains a single positive integer $*k*$ — the number of different prime divisors of $*V*$. Next $*k*$ lines contain prime numbers $*p*_{*i*}$ and their powers $*a*_{*i*}$, separated by spaces. All $*p*_{*i*}$ are different, all $*a*_{*i*} > 0$.

翻译中…

Output

翻译中…

Print $*t*$ lines, on the $*i*$-th line print the answer to the $*i*$-th data set as four space-separated integers: the minimum possible surface area $*S*$ and the corresponding edge lengths $*a*$, $*b*$, $*c*$. If there are multiple variants of the lengths of edges that give the minimum area, you are allowed to print any of them. You can print the lengths of the fridge's edges in any order.

翻译中…

Note

翻译中…

In the first data set of the sample the fridge's volume $*V* = 2^{3} = 8$, and the minimum surface area will be produced by the edges of equal length.

翻译中…

In the second data set the volume $*V* = 17$, and it can be produced by only one set of integer lengths.

翻译中…

样例

Input #1
3
1
2 3
1
17 1
3
3 1
2 3
5 1
Output #1
24 2 2 2
70 1 1 17
148 4 6 5
InputCopy OutputCopy
题目信息
题号
163D
时间限制
5 s
内存限制
256 MB
标签
暴力

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。