Algorithm for Determining Maximum Size for Squares in a Rectangle I'm trying to create a program to draw a specific number of equally-sized squares within a rectangle. I want to set my squares' sizes to the maximum size possible while still fitting within a rectangle. Empty space is fine so long as the squares can't get any larger by breaking into a new row.
Here is an illustration of the desired result of the program with square count values 1-5:

So far, I've successfully found the different permutations for the possible number of columns/rows based on square count. Here's an example using a square count of 4 of the permutations that can contain 4 squares:
{rows: 1, columns: 4}
{rows: 2, columns: 2}
{rows: 2, columns: 3}
{rows: 3, columns: 2}
{rows: 3, columns: 3}
{rows: 4, columns: 1}

Once I have the permutations, how do I determine which one will allow for the maximum square size within the dynamically-sized rectangle? Is there a way to use the area perhaps?
Please let me know if you have any questions or if I can make something clearer. Thank you!
My apologies, I am not very familiar with mathematical notation, so please know this if posting any. I will do my best to research anything posted, but I may have follow-up questions. Thanks!
 A: Dynamically sized rectangle with length $l$ and width $w$.  The largest possible square would have side length $s=\min(l,w)$ (That is the lesser of the length and width)
For programming purposes (depending on the need) it would be easiest to set width and define length as some multiple ($a$) of width. For Example: $w=5$ and $l=7.5$ and $l=aw\implies a=\frac{l}{w}=7.5\div 5=1.5$. Then you can use the $a$ value to determine several things:
If $0<a<1$ then $w>l$ (largest possible square $s=l$);  If $a=1$ then $w=l$ (starting rectangle is square);  If $a>1$ then $w<l$ (largest possible square $s=w$).
$a$ can also be used to determine how many rows/columns of a specific sized square will fit.  If $n$ represents the number of squares desired then you can use a loop to determine if the largest squares possible will fit in a row/column (note: if you force length to always be longer than width it will simplify your programming so that you don't have to consider rows vs. columns)  For example, If we want 7 squares in the rectangle $w=5$ and $l=7.5$ then since $a=1.5$, then $7*1.5>l$ so we consider squares of side length smaller than 1.5.  If we reach an even divisor $k$ (where $k$ is an integer greater than 1) of 1.5 (i.e. $1.5\div 2=.75$, $1.5\div 3=.5$, etc.) then you must account for $k$ rows of squares.  I recommend coming up with some minimum significant digit with which to reduce the square's side length $s$ in the loop.
There are more advanced mathematical approaches to this problem, but purely from a programming perspective, there is some value in keeping it simple.  I hope this helps.
