时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
The following code snippet calculates the sum of the areas of all the sub rectangular grid in a rectangular grid from (0,0) to
%5C%20.)
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 W and H will fit into 64 bit integer, the sum may not be.
示例1
输出
复制
1
16
100
400
27944805889000000