I have a rectangle of size n*m (Where n is a number of rows and m is the number of columns) which is divided into of size 1*1.
I want to calculate the number of the rectangle of size P*Q which contains the cell (x,y) in them.
For example a rectangle of size 3*3 where I need to find all sub-rectangle of size 2*2 which contains the cell (2,2).There will be total 4 such rectangle will be there I may try to solve this by iterating through all cells and find if all points are reachable from this point but it is lots of time-consuming. If any math formula is there which can help.
Assuming $P$ is the number of rows in the covering rectangle, the rows run horizontally and $x$ is measured horizontally from $1$ you need the left corner of the covering rectangle to be in the range from $\max(1,x-Q+1)$ through $\min(x,m-Q)$. Subtract these and add $1$ to get the number of horizontal positions the covering rectangle can be in. Similarly, the number of vertical positions is $1+\min(y,n-P)-\max(1,y-P+1)$. Multiply these two and you are done.