CHAAT4 - Editorial



Author: Dharsan R
Tester: Dharsan R
Editorialist: Dharsan R






Given an integer N, Find the number of unit lines to construct a grid like cube.


In order to construct the cubical grid, consider the base of the grid first. The Base of the grid will look like a square of size N, to build this we can have N+1 horizontal lines of size N parallely one below the other and then N+1 vertical lines of size N parallely one aside the another exactly aligning with the horizontal lines. To build this base we used 2 times N+1 lines and since each line consists of N unit lines, the total number of lines to construct the base alone is 2N(N+1).

Now lets consider the Pillars of the base, each vertices of the base i.e; every point where two or more lines connect will contain a pillar. A base of size N will have exactly (N+1)^2 such vertices.

Consider the base and the pillars together as a floor, to build a grid of size N we need N such floors and finally to account for the ceiling of the grid we can consider it to be another base of size N. Therefore we need N floors where each floor is a combination of (N+1)^2 pillars (aka unit lines )plus a base of size N ( which in turn consists of 2N(N+1) unit lines) and to account for the ceiling we need one more base of size N.

Putting everything into an equation we get,
N*(2N(N+1) + (N+1)^2) + 2N(N+1) = 3N(N+1)(N+1)

Hence in order to build a cubical grid of size N we need 3N(N+1)(N+1) unit line segments.


Setter's Solution
for _ in range(int(input())):