| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 24 | 2 | 1 | 9.091% |
In this problem, you have to find two rectangles with the given total area which have the minimum possible total perimeter.
Recall that the area of a rectangle having sides of length $m$ and $n$ is $m \cdot n,ドル and its perimeter is 2ドル \cdot (m + n)$.
Given an integer $s \ge 2,ドル consider two rectangles with positive integer lengths of sides such that the sum of their areas is $s$. What is the minimum possible sum of their perimeters?
Formally, choose four positive side lengths $a,ドル $b,ドル $c$ and $d$ so that the total area $a \cdot b + c \cdot d$ equals $s$ and the total perimeter 2ドル \cdot (a + b) + 2 \cdot (c + d)$ is minimum possible.
The first line of input contains one integer $s$ (2ドル \le s \le 10^{18}$).
On the first line, print one number: the minimum possible total perimeter. On the second line, print $a$ and $b,ドル the side lengths of the first rectangle, separated by a space. On the third line, print $c$ and $d,ドル the side lengths of the second rectangle, also separated by a space. If there is more than one possible answer, print any one of them.
5
12 1 1 2 2
8
16 3 2 1 2
In the first example, the only optimal answer is to choose squares of sizes 1ドル \times 1$ and 2ドル \times 2$. They can be printed in any order.
In the second example, there is another optimal answer: instead of rectangles 1ドル \times 2$ and 2ドル \times 3,ドル we can choose two squares of size 2ドル \times 2$ each.