Literally 1984
Tom "The Move Semantic" Frew is the manager of AUCPL inc., whether you like it or not. In order to make sure that he can stay busy eating seeds, he has recently hired exactly new employees and needs to set up a cubicle for each of them.
The office floor is a massive empty grid, where each cubicle is a square. Since Tom "The Move Semantic" Frew wants his ducks in a row or whatever how the saying goes, he strictly requires that all
cubicles must be arranged together to form a single, solid
rectangular block (where
and
are positive integers such that
).
To make sure that Tom "The Move Semantic" Frew makes sure that all of his slaves employees are working on his various bird projects, he wants to install glass partitions. A single glass partition has a length of unit. Glass partitions must be placed on every side of every
cubicle.
- If two cubicles are adjacent and share a side, they will share a single glass partition between them.
- Glass partitions must also be placed along the entire outer perimeter of the
rectangular block.
Tom "The Move Semantic" Frew is a cheepskate (haha get it?) and hence wants to choose the dimensions and
of the rectangular block such that the total number of
glass partitions used is minimized.
Given , find the minimum number of glass partitions required.
Input
The only line of each test case contains a single integer (
) — the exact number of cubicles to be built.
Output
For each test case, output a single integer: the minimum number of glass partitions required to build exactly cubicles in a solid rectangular block.
Example
Input 1
4
Output 1
12
Tom "The Move Semantic" Frew can arrange the cubicles as a rectangle or a
rectangle.
- If arranged as
: There are
vertical walls of length
and
horizontal walls of length
. Total partitions =
.
- If arranged as
: There are
vertical walls of length
and
horizontal walls of length
. Total partitions =
.
The minimum number of partitions is .
Input 2
6
Output 2
17
The optimal arrangement is a (or
) rectangle. There will be
vertical walls of length
(requiring
partitions) and
horizontal walls of length
(requiring
partitions). The total is
.
Comments