MUH and House of Cards (找规律+枚举)

19 篇文章 0 订阅
5 篇文章 0 订阅

题目链接:http://codeforces.com/problemset/problem/471/C

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:

  1. The house consists of some non-zero number of floors.
  2. 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.
  3. 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 张卡,问能做成多少种不同楼层(floor)的 house,注意这 n 张卡都要用光。每层 floor 都由一定的 room 构成,每两个相邻 room 规定要有一个公共的ceiling。

思路:不难发现把每一层最左边那根和最右边的那根拿走之后,剩下的都是倒三角(或者是没有了),k层一共拿走2k根,所以若能建成k层,则(n-2*k)%3==0。所以我们只需要枚举k,看看有几个k就可以,那么k的上界是什么?

很明显,建k层用卡片最少的摆放方法是金字塔形,每一层是(3*x-1)根,k层是 k*(3*k+1)/2 根。所以minsumk求出来了。所以k的上界就是minsumk<=n。然后枚举k就可以了。

#include<cstdio>
using namespace std;
typedef long long ll;
ll n;
ll f(ll x){          //建x层最少需要f(x)根 
	return x*(3*x+1)/2;
}
bool judge(int x){   //能不能建成x层 
	return (n-2*x)%3==0;
}
int main(){	
	scanf("%lld",&n);
	int ans=0;
	for(ll i=1;f(i)<=n;i++){
		if(judge(i)) {
			//printf("%lld\n",i);
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
} 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值