CF163D.Large Refrigerator

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 VV . Moreover, Vasya is a minimalist by nature, so the volume should be no more than VV , 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 VV 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 aa , bb , cc are equal to V=abcV=abc and S=2(ab+bc+ca)S=2(ab+bc+ca) , correspondingly.

Given the volume VV , help Vasya find the integer lengths for the refrigerator's edges aa , bb , cc so that the refrigerator's volume equals VV and its surface area SS is minimized.

输入格式

The first line contains a single integer tt ( 1<=t<=5001<=t<=500 ) — the number of data sets.

The description of tt data sets follows. Each set consists of a single integer VV ( 2<=V<=10182<=V<=10^{18} ), given by its factorization as follows.

Let VV = p1a1p2a2... pkakp_{1}^{a_{1}}p_{2}^{a_{2}}...\ p_{k}^{a_{k}} , where pip_{i} are different prime numbers and aia_{i} are positive integer powers.

Then the first line describing a data set contains a single positive integer kk — the number of different prime divisors of VV . Next kk lines contain prime numbers pip_{i} and their powers aia_{i} , separated by spaces. All pip_{i} are different, all a_{i}>0 .

输出格式

Print tt lines, on the ii -th line print the answer to the ii -th data set as four space-separated integers: the minimum possible surface area SS and the corresponding edge lengths aa , bb , cc . 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.

输入输出样例

  • 输入#1

    3
    1
    2 3
    1
    17 1
    3
    3 1
    2 3
    5 1
    

    输出#1

    24 2 2 2
    70 1 1 17
    148 4 6 5
    

说明/提示

In the first data set of the sample the fridge's volume V=23=8V=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=17V=17 , and it can be produced by only one set of integer lengths.

首页