generate functionWed, 01 Mar 2023

Vanya was given n cubes for her birthday. He and his friends decided to build a pyramid out of them. Vanya wants to build a pyramid in the following way: there should be 1 cube at the top of the pyramid, 1 + 2 = 3 cubes at the second level, 1 + 2 + 3 = 6 cubes at the third level, and so on. Thus, at the i-th level of the pyramid there should be 1 + 2  + (i -1) + i cubes. Print in a single line the maximum possible height of the pyramid. Input data The first line contains an integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya. Output Print in a single line the maximum possible height of the pyramid.

def max_level_of_pyramid(n): level = 0 while True: if n == 0: return level n -= level level += 1 max_level_of_pyramid(10)

Questions about programming?Chat with your personal AI assistant