A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h−1 onto a base. A base consists of h pyramids of height 1, and h−1 cards on top. For example, card pyramids of heights 1, 2, and 3 look as follows:
You start with n cards and build the tallest pyramid that you can. If there are some cards remaining, you build the tallest pyramid possible with the remaining cards. You repeat this process until it is impossible to build another pyramid. In the end, how many pyramids will you have constructed?
高度為 1 的紙牌金字塔是通過將兩張紙牌相互放置來構建的。 對於 h>1,高度為 h 的卡片金字塔是通過將高度為 h-1 的卡片金字塔放置在底座上來構建的。 一個底座由 h 個高度為 1 的金字塔和頂部的 h-1 張卡片組成。 例如,高度為 1、2 和 3 的卡片金字塔如下所示:
您從 n 張卡片開始,並儘可能地建造最高的金字塔。 如果還有一些牌,你可以用剩餘的牌建造最高的金字塔。 你重複這個過程,直到不可能建造另一個金字塔。 最後,你會建造多少個金字塔?
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains a single integer n (1≤n≤109) — the number of cards.
It is guaranteed that the sum of n over all test cases does not exceed 109.
每個測試由多個測試用例組成。 第一行包含一個整數 t (1≤t≤1000)——測試用例的數量。 接下來的 t 行包含測試用例的描述。
每個測試用例包含一個整數 n (1≤n≤109)——卡片的數量。
保證所有測試用例的 n 總和不超過 109。
For each test case output a single integer — the number of pyramids you will have constructed in the end.
對於每個測試用例,輸出一個整數 — 你最終將構建的金字塔的數量。
5 3 14 15 24 1
1 2 1 3 0
In the first test, you construct a pyramid of height 1 with 2 cards. There is 1 card remaining, which is not enough to build a pyramid.
In the second test, you build two pyramids, each of height 2, with no cards remaining.
In the third test, you build one pyramid of height 3, with no cards remaining.
In the fourth test, you build one pyramid of height 3 with 9 cards remaining. Then you build a pyramid of height 2 with 2 cards remaining. Then you build a final pyramid of height 1 with no cards remaining.
In the fifth test, one card is not enough to build any pyramids.
在第一個測試中,你用 2 張卡片構建一個高度為 1 的金字塔。 還剩 1 張卡,不足以建造金字塔。
在第二個測試中,你建造了兩個金字塔,每個高度為 2,沒有剩餘的牌。
在第三個測試中,你建造一個高度為 3 的金字塔,沒有剩餘的牌。
在第四個測試中,您構建一個高度為 3 的金字塔,剩餘 9 張卡片。 然後你建立一個高度為 2 的金字塔,剩餘 2 張牌。 然後你建立一個高度為 1 的最終金字塔,沒有剩餘的牌。
在第五次測試中,一張卡片不足以建造任何金字塔。
ID | User | Problem | Subject | Hit | Post Date |
沒有發現任何「解題報告」 |