#P2241. Counting Squares and Non-square Rectangles on a Chessboard

    ID: 15520 Type: Default 1000ms 256MiB

Counting Squares and Non-square Rectangles on a Chessboard

Counting Squares and Non-square Rectangles on a Chessboard

Given an \(n \times m\) chessboard, your task is to compute the number of squares and the number of rectangles that are not squares.

The number of squares can be computed using the formula:

[ \text{Squares} = \sum_{i=1}^{\min(n,m)} (n - i + 1)(m - i + 1) ]

The total number of rectangles (including squares) is:

[ \text{Rectangles} = \frac{n(n+1)m(m+1)}{4} ]

Thus, the number of rectangles that are not squares is obtained by subtracting the number of squares from the total number of rectangles.

inputFormat

The input consists of two positive integers n and m (\(1 \leq n, m \leq 10^4\)), representing the number of rows and columns of the chessboard respectively. The two integers are provided on a single line separated by a space.

outputFormat

Output two integers separated by a space: the first number is the total count of squares and the second number is the count of rectangles that are not squares.

sample

1 1
1 0