Description
Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows:the top level of the pyramid must consist of 1 cubes, the second level must co Nsist of 1 + 2 = 3 cubes, the third level must has 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must has 1 + 2 + ... + (i -1) + i cubes.
Vanya wants to know, the maximum height of the pyramid, the he can make using the given cubes.
Input
The first line contains an integer n (1≤ n ≤104)-the number of cubes given to Vanya.
Output
Print the maximum possible height of the pyramid in the
Sample Input
Input
1
Output
1
Input
25
Output
4
Hint
Illustration to the second sample:
problem-solving ideas : First need a control program to end the statement (that is, we have the number of cubes larger than the total number of squares required for the building) and then need two number T and S (used to accumulate the number of cubes required for each layer and the total number of cubes required) Finally, a judgment statement is used to determine whether the number of squares we have can meet the building of these floors, if not enough can only be built to complete the construction of h-1 floor.
Program code:
#include <iostream>
#include <stdio.h>
using namespace std;
Main ()
{
int n,h=0,t=0,s=0;
scanf ("%d", &n);
while (s<n)//Conditions for program execution
{
h++;
T=t+h;
S=s+t;
}
if (n<s)//Determine whether the number of cubes we have can meet the building of these floors
H=h-1;
printf ("%d\n", h);
return 0;
}
ACM uses n cubes to build pyramids how many layers can be built?