Title description
A chessboard with an N×M grid (1≤N≤100, 1≤M≤100)
Find out how many squares and rectangles (excluding squares) are contained in the board.
For example: when N=2, M=3:
There are 8 squares: that is, 6 squares with a side length of 1;
There are two squares with side length 2.
There are 1010 rectangles:
which is
There are 4 2×1 rectangles
There are 3 1×2 rectangles:
There are two 3×1 rectangles:
There is one 3×2 rectangle:
As in the above example: input: 2,3
Output: 8,10
Input format
N, M
Output format
Number of squares and number of rectangles
Input and output sample
Input #1
2 3
Output #1
8 10
Description/Prompt
[Question source]
NOIP 1997 Universal Group Question 1
Code:
//P1548 棋盘问题
#include<iostream>
using namespace std;
long long n,m,b,a;
int main()
{
cin>>n>>m;
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
if(i==j) a+=(n-i)*(m-j);//如果i==j,说明是正方形
else b+=(n-i)*(m-j);//如果不等说明是矩形
cout<<a<<" "<<b<<endl;
return 0;
}