n, build an n × n × n cube. The cell at (x, y, z), where 0 ≤ x, y, z < n, holds the number x * (y | z), with | meaning bitwise OR.
The cost of a cube is the sum of the numbers in all its cells. Given an integer budget, return the largest side n for which the cost of the cube does not exceed budget.
A cube of side 1 always costs 0, so the answer is at least 1.budget=3 → 2
For n = 2 only the cells with x = 1 are non-zero: 1·(0|1) + 1·(1|0) + 1·(1|1) = 3, exactly the budget. For n = 3 the total is already 45.
budget=44 → 2
A cube of side 3 costs 45, one more than the budget, so the answer is 2.
budget=0 → 1
A cube of side 1 is a single cell (0, 0, 0) with value 0, so it fits any budget.
budget=3
2
Run checks the first 3 tests in your browser. Submit checks all 65 tests on the server, hidden ones included.