Your task is to build a structure with \$n\$ cubes. The volume of cubes follow the following sequence (bottom -> top)
\$n^3, (n-1)^3, (n-2)^3,...,1^3\$
The total volume of the structure (\$V\$).
value of (\$n\$), i.e : The total number of cubes.
\$V = n^3 + (n-1)^3 + .... + 1^3\$
- Input will always be an integer.
- Sometimes it isn't possible to follow the sequence, i.e : \$V\$ doesn't represent a specific value for \$n\$. In that event return -1, or a falsy value of your choosing (consistency is required though).
- This is code-golf so shortest answer in bytes for each language wins.
- No answer will be marked accepted for the above mentioned reason.
- This is my first challenge on the site so bear with me, and forgive (and tell me about) any mistakes that I made.
- Kindly provide a link so your code can be tested.
- If you can, kindly write an explanation on how your code works, so others can understand and appreciate your work.
input : 4183059834009 output : 2022 input : 2391239120391902 output : -1 input : 40539911473216 output : 3568
Thanks to @Arnauld for the link to this :
Isn't that nice.
Link to orignial : Link