All the Squares
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
Discussion (opens after you solve — no spoilers before)
No comments yet.