Problems > All the Squares

All the Squares

Difficulty: 1300 3000 ms 128 MB

math

How many axis-aligned SQUARES (of any size) does an N×M grid contain?

Input: one line with two integers N and M.

Output:i=1..min(N,M) (N−i+1)(M−i+1).

Constraints:

  • 1 ≤ N, M ≤ 105

Sample Tests

Input 1
2 3
Output 1
8
Input 2
1 5
Output 2
5

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.