Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Squares Inside Square

By fsshakkhor · Limits 1s, 512 MB

Hello , Programmers. There is one thing that I don’t like about competitive problem solving, which is - huge problem statement. The problem setters often build up a story which is not even related to the actual problem. And that is exactly the thing I am doing right now. Let’s move on to the problem.

You have been given a N x N grid. You have to count the total number of different squares inside it. The sides of the square are parallel to the axes of the grid.

For example, the following 3 x 3 grid has one (3 x 3) square, four (2 x 2) squares and nine (1 x 1) squares. Total 14 squares. Only the (2 x 2) and (3 x 3) squares have been shown in the diagram.


The first will contain an integer T (1 ≤ T ≤ 10000) denoting the number of test cases.

Each of the next **T lines will contain an integer N (1 ≤ N ≤ 2000000).


For each test case print the answer in a new line. It is guaranteed that the answer will fit into 64-bit signed integer.





78% Solution Ratio

nahidhasan98Earliest, 11M ago

sakibalaminFastest, 0.0s

sakibalaminLightest, 262 kB

mdvirusShortest, 62B


Login to submit

Related Contests

Stamford University Bangladesh Summer Contest 2019 Ended at 2019-05-03 07:00:00 +0000 UTC
Replay of Stamford University Bangladesh Summer Contest 2019 Ended at 2019-05-03 18:00:00 +0000 UTC