Building Tower

5

1 votes
, Basic Math, C++, Math, Observation
Problem

Alex wants to build a tower of height N levels. He wants to build the tower as follows: the ith level of the tower must have 1+2+...+(i1)+i blocks, i.e., the top level of the tower must consist of 1 block, the second level must consist of 1+2=3 blocks, the third level must have 1+2+3=6 blocks, and so on. The numbering of levels is done from top to bottom.

Find the total number of blocks required to build a tower of height N.

Input Format:

  • The first line contains an integer T, which denotes the number of test cases.
  • The first line of each test case contains one integer N, denoting the height of the tower.

Output Format:

For each test case, print the total number of blocks required to build a tower of height N.

Constraints:

1<=T<=103

1<=N<=105

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For first test case:
N=4, Alex uses 1 block on the 1st level, 3 blocks on the 2nd level, 6 blocks on the 3rd level, and 10 blocks on the 4th level of the tower. So, the total number of blocks required is 1+3+6+10=20. Hence, 20 is the answer.

For second test case:
N=1, Alex uses 1 block on the 1st level of the tower. So, the total number of blocks required is 1. Hence, 1 is the answer.

Editor Image

?