Arrange $n$ tiles in a rectangle pattern Is there a way to find how to arrange $n$ tiles in order to form a rectangle that is closest to a square? As I result I am looking for the dimension of that rectangle if it exists.
For example, here are the results I expect from $1$  to $9$.


*

*a 1 by 1 square, fairly simple.

*a 1 by 2 rectangle.

*a 1 by 3 rectangle.

*a 2 by 2 square.

*this is impossible because a 1 by 5 rectangle is thinner than the previous shape.

*a 2 by 3 rectangle.

*this is impossible.

*a 2 by 4 rectangle.

*a 3 by 3 square.


I am only looking at $n$ smaller than $100$ but would rather not have to hardcode everything.
 A: Although your problem statement doesn't explicitly state it, your examples indicate that you want the value of the lower of the $2$ factors to never decrease. Thus, each increase of the lower factor among your examples occurs at a square, such as $1$ being $1 \text{ by } 1$, $4$ being $2 \text{ by } 2$ and $9$ being $3 \text{ by } 3$.
If this is a correct assumption on my part, and there are no other unstated conditions, then each next value which is not "impossible" would be the integers which are multiples of the current "low" factor until you encounter the square of the next higher integer.  Thus, continuing from what you have written, the next valid values would be $12 = 3 \times 4$ and $15 = 3 \times 5$ for a lower value of $3$ before you hit the next square at $16 = 4 \times 4$.  From there, the next values would be $20 = 4 \times 5$ and $24 = 4 \times 6$ before you encounter $25 = 5 \times 5$. You can then continue like this until you reach $100$ or most any other limit you care to set.
To check for any specific value representing a valid rectangle, including what its shape would be, or if it's impossible, you need to determine what the largest perfect square is less or than or equal to your number. This can be done by using the integer part of the square root. For example, the square root of $143$ is $11.9\ldots$ so the factor to check is $11$.  As $143 = 11 \times 13$, it is a valid rectangle.  However, $142$ down to $133$ will not work, with $132 = 11 \times 12$ being the next smaller value which would work.
As previously written by Ross Millikan in the comments below, stated more succinctly using mathematical terminology, for any positive integer $n$, determine $k = \lfloor \sqrt{n} \rfloor$. If $k$ divides $n$, then the rectangle is $k \times \frac{n}{k}$, else it's impossible.
