ACM Second Competition (C)

Source: Internet
Author: User

Time limit:1000MS Memory Limit:262144KB 64bit IO Format:%i64d &%i6 4u

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 MU St consist 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.< /c15>

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

Program Analysis: The test point of this problem is still accumulated. The first time is 1, the second is 1+2, the third is 1+ (1+2) +3 so cycle, so this also requires that we should put each of the answers in a number, for this topic we use an array to solve the problem, in a for loop to add the number to add in. But it should be noted that at the end of our sum-n>0 we were adding more than N, so J should be minus 1. But if sum==0, then the value of J is the value we want to get.

Program code:

#include<cstdio>#include<iostream>UsingNamespace Std;IntMain(){int a[200]={0};int INJ, Sum=0; a[1]=1;For(I=2; I<200; I++){For(j=0; j<=i; j+ +) A[I]+=j;}scanf("%d", &n);For(j=1; j<=i; j++){Sum+=a[j];If(Sum>n){Printf("%d\n ",j-1< Span class= "Sh-symbol"); break;} else if (Sum== N {printf (  "%d\n" ,j< Span class= "Sh-symbol"); break;} }return 0;< Span class= "Sh-cbracket" >              

ACM second race (C)

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.