#K5931. Pyramid Blocks

    ID: 30836 Type: Default 1000ms 256MiB

Pyramid Blocks

Pyramid Blocks

You are given a number of blocks n. Your task is to determine whether it is possible to form a pyramid using all the n blocks. The pyramid is constructed by placing consecutive natural numbers starting from 1, where the first row contains 1 block, the second row contains 2 blocks, the third row contains 3 blocks, and so on.

Mathematically, a pyramid with k levels uses a total of $$\frac{k(k+1)}{2}$$ blocks. Thus, if \( n = \frac{k(k+1)}{2} \) for some positive integer \( k \), then a perfect pyramid can be formed.

If it is possible to build such a pyramid, output "YES" on the first line followed by k lines where the i-th line contains i consecutive numbers representing that level of the pyramid. Otherwise, output "NO".

inputFormat

The input is read from standard input (stdin). The first line contains an integer T, the number of test cases. Each of the next T lines contains a single integer n representing the number of blocks.

outputFormat

For each test case, if it is possible to form a pyramid using all the blocks, print "YES" on the first line and then print the pyramid levels on the subsequent lines (each level on a new line). If it is not possible, print "NO". The output for all test cases is written to standard output (stdout) sequentially.## sample

3
3
6
5
YES

1 2 3 YES 1 2 3 4 5 6 NO

</p>