您的位置:首页 > 其它

MUH and House of Card

2016-12-08 12:27 411 查看
**

MUH and House of Card

**s

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they’ve already found a hefty deck of n playing cards. Let’s describe the house they want to make:

The house consists of some non-zero number of floors.

Each floor consists of a non-zero number of rooms and the ceiling. A room is two cards that are leaned towards each other. The rooms are made in a row, each two adjoining rooms share a ceiling made by another card.

Each floor besides for the lowest one should contain less rooms than the floor below.

Please note that the house may end by the floor with more than one room, and in this case they also must be covered by the ceiling. Also, the number of rooms on the adjoining floors doesn’t have to differ by one, the difference may be more.

While bears are practicing to put cards, Horace tries to figure out how many floors their house should consist of. The height of the house is the number of floors in it. It is possible that you can make a lot of different houses of different heights out of n cards. It seems that the elephant cannot solve this problem and he asks you to count the number of the distinct heights of the houses that they can make using exactly n cards.

Input

The single line contains integer n (1 ≤ n ≤ 1012) — the number of cards.

Output

Print the number of distinct heights that the houses made of exactly n cards can have.

Examples

input

13

output

1

input

6

output

0

Note

In the first sample you can build only these two houses (remember, you must use all the cards):



Thus, 13 cards are enough only for two floor houses, so the answer is 1.

The six cards in the second sample are not enough to build any house.

题意:这里题目背景较繁琐,推荐了解了大概信息之后直接根据样例和图片对照理解。题目所表述意思即有n张卡牌,要求按图样搭出层数尽量高的房子。且底层一定要大于上层。

思路:这题需要多画图,从画图中找到规律,即第k层至少需要的卡牌数量为3*k-1;(如3层高的房子,第二层需要的卡牌数为3*2-1==5;第三层需要3*3-1==8;)而达到第i层需要的卡牌数为(3*i+1)*i/2;(三层高的房子需要卡牌的总数为15;)

根据上述规律,可以得到(3*i+1)*i/2<=n;以此可以作为条件。而3*k-1这个条件的作用,就是用来判断是否层数+1。在搭房子的过程中会发现,每一层会跟3的倍数少1,即有k层则跟3的倍数少k。

代码实现:

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
long long n;
scanf("%lld",&n);
long long i,cnt=0;;
for (i=1;(3*i+1)*i/2<=n;i++)
{
if ((n+i)%3==0) cnt++;
}

printf ("%lld\n",cnt);
}


引用

http://www.2cto.com/kf/201503/383428.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: