neon v
neon v

Reputation: 1

how to count how many squares with different sizes in a grid with size n*m?

is there a formula to count each distinct square or rectangle within a rectangle for e.g if we have rectangle of size 105119*753919 , and we want to know how many 54705*91121 in it or how many 2*2 in it , is there a general formula that we can use to get the count ?

Upvotes: 0

Views: 288

Answers (1)

L. Scott Johnson
L. Scott Johnson

Reputation: 4382

In an nm grid, how many ij rectangles?

Answer: as many as places you can put the upper left corner. That is:

(n-i+1)*(m-j+1)

Upvotes: 1

Related Questions