CodeForces 471C MUH and House of Cards
After reading the Hint graph of the question, you can see that the number of cards required for each layer is 2 * n + (n-1, then there is a general idea: brute-force enumeration, but there is no way to enumerate it. This formula only represents one layer. It is impossible to enumerate each layer, the formula can be reduced to 3 * n-1, so that 1 is a multiple of 3, and 1 is different for each layer. If there is an I layer, it is actually worse than I, so it is easy to think of. Assuming there are a total of x cards, it is actually enumerating I, how many I makes (x + I) % 3 = 0, this is simple, but there is a limit, because you need to know the number of cards required to build the I layer, and the Buen has more than x cards, I need to draw more pictures here, and later I found that building layer I requires at least (3 * I + 1) * I/2 cards, so that it is easy to determine the enumerated range, and the answer is not big, so it's okay to enumerate the answer directly.
Question link: click here
I thought it was a little tricky. If the answer was too big, I would just look at what others did and find a better way. In fact, the difference between each layer is a multiple of 3, which is equivalent, subtraction of 2 on each layer is a multiple of 3, which is not an enumeration (x + I) % 3 = 0. You can enumerate down (x-3 * (j-1) -2 * j) % 3 = 0; therefore, you do not need to consider the upper limit, which reduces the time used to find the formula.
Ll n; void init () {} bool input () {while (cin> n) {return false;} return true;} void cal () {ll ans = 0ll; for (ll k = 1; k ++) {if (n <(3 * k + 1) * k/2) break; if (n + k) % 3 = 0) ans ++;} cout <