ACM用N个正方体来建造金字塔问可以建造多少层

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 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.

Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.

Input

The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.

Output

Print the maximum possible height of the pyramid in the single line.

Sample Input

Input

1

Output

1

Input

25

Output

4

Hint

Illustration to the second sample:

 

解题思路首先需要一个控制程序结束的语句(也就是要我们所拥有的正方体数大于我们所建楼层所需的总的正方体数)然后需要两个数 t和s(用来分别累加每层需要的正方体数和总共需要的正方体数)最后用一个判断语句判断我们所拥有的正方体数是否可以满足这些楼层的建设;如果不能满足就只能建设完成 h-1层楼的建设。

程序代码:

#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    int n,h=0,t=0,s=0;
      scanf("%d",&n);
      while(s<n) //控制程序执行的条件
      {
            h++;
            t=t+h;
            s=s+t;
      }
      if(n<s) //判断我们所拥有的正方体数是否可以满足这些楼层的建设
            h=h-1;
      printf("%d\n",h);

return 0;
}

转载于:https://www.cnblogs.com/xinxiangqing/p/4654814.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值