题目
Description
Here is an n×m grid, which is made up of 1×1 lattices. You can find many rectangles with different sizes in the grid. Can you calculate the total area of all rectangles?
For example, there is a 2×4 grid in the following figure, and the answer is 80, which equals to 8×1 + 6×2 + 4×3 + 2×4 + 4×2 + 3×4 + 2×6 + 1×8. That means there are eight 1×1, six 1×2, four 1×3, two 1×4, four 2×1, three 2×2, two 2×3 and one 2×4 rectangles.
Input
There are several test cases.
Each case contains two integers n and m (1 ≤ n, m ≤ 100), denoting the height and width of the grid.
Output
For each test case, print one line containing the total area of all rectangles in the grid.
Sample Input
1 1 2 4
Sample Output
1 80
举个3*3例子吧
9*1*1 6*1*2 3*1*3
6*2*1 4*2*2 2*2*3
3*3*1 2*3*2 1*3*3
第一行9=(3-1+1)*(3-1+1)
6=(3-1+1)*(3-1+2)
3=(3-1+1)*(3-1*3)
以此类推得到一个公式
从h*m里面选一个a*b的
个数c=(h-a+1)*(m-b+1)------找位置
代码如下
PS:这道题本身不难,但是找位置,从他的几何意义来考虑的思想很好
补充:印象中还有一个题说的是n*n的正方形被分成n*n份
问一共有多少个正方形?
这个题只有一个变量,可以考虑数列。