Requirement
Tim and his pyramid from Cubes
Tim just finished his lunch and was playing around in the after school centre. He would be daily being provided with various toys and books to while away his time until his mom comes to pick him up.
That day at school his teacher taught him an origami work on making a pyramid. He tried making them in papers and succeeded.
Tim suddenly got an idea to replicate the pyramid using the colourful cubes he had around him.
Tim wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... + ( i - 1) + i cubes.
Tim wants to know what would be the maximum height of the pyramid that he can make using the given cubes. Let us help him sort it out.
Input Format:
The input contains an integer n (1 ≤ n ≤ 10000), which corresponds to the number of cubes given to Tim.
Output Format:
Print the maximum possible height of the pyramid in the single line.
Sample Input1:
1
Sample Output1:
1
Sample Input2:
25
Sample Output2:
4
01#include02intmain()03{04intn,sum=0,i=1;05scanf("%d",&n);06while(1)07{08sum+=(i*(i+1))/2;09if(sum>n)10break;11i++;12}13printf("%d",i-1);14return0;15}

No comments: