codeforces 471C MUH and House of Cards 数论

来源:互联网 发布:淘宝退货骗局给假地址 编辑:程序博客网 时间:2024/06/04 19:32

题目链接:cf 471C

        

C. MUH and House of Cards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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:

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

Sample test(s)
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根火柴如上图一样搭建房屋的层数有多少种

      不难发现,每一行的火柴减去边上的2根之后都是3的倍数,(n-2×k)%3==0时 构成了k层,k层最少需要(k-1)*k/2*3根火柴,循环找出可行k即可

/****************************************************** * File Name:   c.cpp * Author:      kojimai * Creater Time:2014年09月27日 星期六 00时03分32秒******************************************************/#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<iostream>using namespace std;int main(){long long n;cin>>n;long long ans=0;long long cnt=0;long long all;if(n%3==0){cnt = 3;n-=6;}else if(n%3==1){cnt = 2;n-=4;}else{cnt = 1;n -= 2;}while(n>=0){all=(cnt-1)*cnt/2;if(n/3<all)break;elseans++;n-=6;cnt+=3;}cout<<ans<<endl;return 0;}


0 0
原创粉丝点击