Problem Statement
Consider a N-level pyramid built of unit cubes. An example for N=3 can be seen in the image below.

Formally, a pyramid of size N has N levels, where the i-th level (counting from the top) contains an i by i grid of unit cubes.
You have K cubes. First, you select a suitable pyramid size as follows: If K is exactly the number of cubes necessary to build a pyramid of size N for some N, you pick that size. Otherwise, you pick the smallest pyramid size you can not build.
Now you start building the pyramid in a systematic bottom-up way. First you build the complete bottom level, then you build the level above that, etc. When building a level, also proceed in a systematic way, starting the next row only when the previous one is full.
For example, for 21 cubes you should get the following incomplete pyramid:

Given an
Definition
- Class:
- PyramidOfCubes
- Method:
- surface
- Parameters:
- int
- Returns:
- double
- Method signature:
- double surface(int K)
- (be sure your method is public)
Notes
- The returned value must be accurate to within a relative or absolute value of 1E-9.
- The bottom sides of the cubes on the bottommost level are a part of the surface.
Constraints
- K will be between 1 and 1,000,000,000, inclusive.
Examples
14
Returns: 42.0
The first example from the problem statement.
21
Returns: 58.0
The second example from the problem statement.
1
Returns: 6.0
A single cube.
2
Returns: 10.0
Two cubes next to each other.
451234
Returns: 47498.0
Quite a lot of cubes.
3
Returns: 14.0
4
Returns: 16.0
5
Returns: 20.0
6
Returns: 22.0
7
Returns: 26.0
8
Returns: 28.0
9
Returns: 30.0
10
Returns: 34.0
11
Returns: 36.0
12
Returns: 38.0
13
Returns: 38.0
14
Returns: 42.0
15
Returns: 46.0
16
Returns: 48.0
17
Returns: 52.0
18
Returns: 54.0
19
Returns: 56.0
20
Returns: 58.0
22
Returns: 58.0
23
Returns: 60.0
24
Returns: 60.0
25
Returns: 60.0
26
Returns: 64.0
27
Returns: 66.0
28
Returns: 68.0
29
Returns: 68.0
30
Returns: 72.0
31
Returns: 82.0
32
Returns: 82.0
33
Returns: 82.0
54406261
Returns: 1193556.0
54406260
Returns: 1193552.0
54406259
Returns: 1193552.0
54406258
Returns: 1193550.0
54406262
Returns: 1179506.0
998441521
Returns: 8308806.0
998441520
Returns: 8308802.0
998441519
Returns: 8308802.0
998441518
Returns: 8308800.0
998441500
Returns: 8308780.0
998441522
Returns: 8252782.0
998441523
Returns: 8252782.0
1000000000
Returns: 8293536.0
123456789
Returns: 2050182.0
987654321
Returns: 8227570.0
12433215
Returns: 441910.0
53253322
Returns: 1163598.0
2143565
Returns: 135884.0
547654743
Returns: 5538756.0
135784784
Returns: 2188118.0
934673245
Returns: 7921618.0
954332132
Returns: 8024148.0
123453163
Returns: 2050094.0
123
Returns: 186.0
5433
Returns: 2466.0
4
Returns: 16.0
3
Returns: 14.0
10
Returns: 34.0
6
Returns: 22.0
5
Returns: 20.0
26
Returns: 64.0
15
Returns: 46.0
9
Returns: 30.0
998441521
Returns: 8308806.0
983475384
Returns: 8202462.0
17
Returns: 52.0
1000000000
Returns: 8293536.0
25
Returns: 60.0
500000000
Returns: 5204004.0
913687900
Returns: 7778014.0
18
Returns: 54.0
7
Returns: 26.0