| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 512 MB | 238 | 112 | 77 | 44.253% |
The following code snippet calculates the sum of the areas of all the sub rectangular grid in a rectangular grid from (0,0) to (N,N). Find an efficient way to compute that.
sum = 0
for r1 = 0 to N-1
for c1 = 0 to N-1
for r2 = r1+1 to N
for c2 = r2+1 to N
sum = sum + (r2-r1)*(c2-c1)
print(sum)
Input starts with T the number of test cases. Each test case consists of a single integer N.
For each test output the sum (as computed above). Please note that even though N will fit into 64 bit integer, the sum may not be.
5 1 2 3 4 1000
1 16 100 400 27944805889000000