Problem B - Card Constructions (构造)_c++

题意:

你可以用图示的方法建造金字塔,但是每一次都要建最大的金字塔,问最后能建几个金字塔。

思路:

我们可以发现对于每一个金字塔都是两边增加了两天边,然后中间行数− 1 -1−1个三角形,所以就可以求出每一个金字塔的边数
\(∑ _{i = 0} ^k i ∗ 3 + 2\),然后从最大的金字塔开始遍历,如果可以建造的话,就一直减去对应的边数,然后重复此过程

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll _, n, m, a[1000];
int main() {
	//freopen("in.txt", "r", stdin);
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> _; while (_--) {
		cin >> n; m = 0;
		while (n > 1) {
			ll k = 2;
			m++;
			while (n >= k)n -= k, k += 3;
		}
		cout << m << endl;
	}
}

The desire of his soul is the prophecy of his fate
你灵魂的欲望,是你命运的先知。