# Rectangles in rectangles

## Python 2, 66 59 bytes

lambda n,k:sum(a%n*(n-a%n)==a/n*(k-a/n)for a in range(n*k))


Try it online!

Each possible rectangle inside the $$\n \times k\$$-rectangle can be specified by two integers, $$\0 \le a \lt n\$$ and $$\0 \le b \lt k\$$:

To verify a rectangle given $$\a\$$ and $$\b\$$, it suffices to check if one angle is a right angle. To do this I take the dot product of $$\\binom{b}{0}-\binom{0}{a}=\binom{-b}{a}\$$ and $$\\binom{k-b}{n}-\binom{0}{a}=\binom{k-b}{n-a}\$$ to check whether the angle at $$\\binom{0}{a}\$$ is a right angle:

$$\langle \left( \begin{matrix} -b \\ a \\ \end{matrix}\right), \left(\begin{matrix} k-b \\ n-a \\ \end{matrix} \right) \rangle = 0 \\\Leftrightarrow a\cdot(n-a)-b\cdot(k-b)=0 \\\Leftrightarrow a\cdot(n-a)=b\cdot(k-b)$$

## 05AB1E, 10 8 bytes

LDI-*¢O


Try it online!

Commented:

          # implicit input: [n, k]
L         # for both values take the [1..x] range
#   [[1,...,n], [1,...,k]]
D        # duplicate this list
I       # push the input [n,k]
-      # subtract this from the ranges
#   [[1-n,...,n-n], [1-k,...,k-k]]
#  =[[-n+1,...,0], [-k+1,...,0]]
*     # multiply with the ranges
#   [[1*(-n+1),...,n*0], [1*(-k+1),...,k*0]]
# push all lists of this list on the stack
¢   # count the occurences of each value of one list in the other
O  # sum those counts


## C (gcc), 63 61 bytes

Saved 2 thanks to ceilingcat!!!

s;a;f(n,k){for(s=a=n*k;a--;)s-=a%n*(n-a%n)!=a/n*(k-a/n);a=s;}


Try it online!