ACM uses n cubes to build pyramids how many layers can be built?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.