Two Rectangles

시간 제한2초메모리 제한1024 MB

요약
총넓이가 s인 두 직사각형의 변을 양의 정수로 정할 때 두 둘레의 합이 최소가 되는 값을 구한다.
난이도

어려움10점 중 8점

유형
수학, 정수론, 그리디, 완전 탐색
정답자
아직 제출이 없습니다

문제

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 mm and nn is m⋅nm \cdot n, and its perimeter is 2⋅(m+n)2 \cdot (m + n).

Given an integer s≥2s \ge 2, consider two rectangles with positive integer lengths of sides such that the sum of their areas is ss. What is the minimum possible sum of their perimeters?

Formally, choose four positive side lengths aa, bb, cc and dd so that the total area a⋅b+c⋅da \cdot b + c \cdot d equals ss and the total perimeter 2⋅(a+b)+2⋅(c+d)2 \cdot (a + b) + 2 \cdot (c + d) is minimum possible.

입력

The first line of input contains one integer ss (2≤s≤10182 \le s \le 10^{18}).

출력

On the first line, print one number: the minimum possible total perimeter. On the second line, print aa and bb, the side lengths of the first rectangle, separated by a space. On the third line, print cc and dd, 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.

힌트

In the first example, the only optimal answer is to choose squares of sizes 1×11 \times 1 and 2×22 \times 2. They can be printed in any order.

In the second example, there is another optimal answer: instead of rectangles 1×21 \times 2 and 2×32 \times 3, we can choose two squares of size 2×22 \times 2 each.

예제2

  1. 예제 1

    입력
    5
    
    예상 출력
    12
    1 1
    2 2
    
  2. 예제 2

    입력
    8
    
    예상 출력
    16
    3 2
    1 2