Assil vs Ramses II
Written by Iyed Baassou
Problem Statement
Solution
* We denoted the given number of boxes as .
We can notice that the number of boxes in layer is
Thus we can find the number of layers by subtracting , , , ... , from until it's negative.
This can be reformulated as the greatest such that
We can implement this with a while loop with the condition sum + i**2 <= x and we keep adding to sum and increasing the base of and the number of layers.
The output will be layers as number of layers and x - sum as the count of remaining boxes.
Implementation
For sake of simplicity, we will be implementing the solution in Python.
py
x = int(input())
i = 1
sum = 0
layers = 0
while sum + i**2 <= x:
layers += 1
i += 1
sum += i**2
print(layers)
print(x - sum)
