As far as I understand, you want to place n rectangles with fixed C=W/H ratio on the wall with given Width and Height
Let rectangle height is h (unknown yet), width is w = C * h
Every row of grid contains
nr = Floor(Width / (C * h)) // rounding down
Every column contains
nc = Floor(Height / h)
Write inequality
n <= nc * nr
n <= Floor(Width / (C * h)) * Floor(Height / h)
and solve it (find maximal possible h value) for unknown h
For real values of parameters h might be found getting initial approximate value:
h0 = Ceil(Sqrt(Width * Height / (n * C)))
and decrementing h value until inequality becomes true
solved Find size of rectangles to fill area