I need to pack $N$ identical squares arranged in array fashion, $R$ rows of $C$ columns, the last row possibly incomplete, in a $W\times H$ rectangle (reals). The squares must be as large as possible.
With $S$ the side of the squares, this leads to the system of inequations
$$\begin{cases}CS\le W,\\RS\le H,\\CR\ge N.\end{cases}$$
Multiplying the first two and dividing by the third,
$$S^2\le\frac{WH}N.$$
My first naïve approach was to compute $S$ by assuming that the equality holds and deduce
$$C=\left\lfloor\frac WS\right\rfloor,R=\left\lfloor\frac HS\right\rfloor.$$
But this is wrong as the third inequation can be invalidated.
My second approach is by trying every possible value of $C$ from $1$ to $N$, deducing $R$ from $CR\ge N$, then $S$. Hence, finding the $C$ that maximizes
$$\min_C\left(\frac WC,\frac H{\left\lceil\dfrac NC\right\rceil}\right)$$ or minimizes $$\max_C\left(\frac HWC,\left\lceil\dfrac NC\right\rceil\right).$$
I suspect that there should be a closed-form solution, probably close to my naïve estimate, but so far I haven't found a line of attack. Can you help ?
Update:
Following @DarthGeek, the solution is found where $\dfrac{\left\lceil\dfrac NC\right\rceil}C$ crosses $\dfrac HW=:a$. This function is piecewise linear and monotonic. As we are only interested in values at integers, a linear or dichotomic search can do.
From $$\frac NC\le\left\lceil\frac NC\right\rceil<\frac NC+1$$
we deduce that the solution will lie in $$\left[\sqrt{\frac{N}a},\sqrt{\frac{N}a+\frac1{4a^2}}+\frac1{2a}\right).$$

I don't have a "strong" proof for this solution but I think this is the right one.
For each set $W,H,N$ there are $N$ possible configurations:
$$C = n\quad R = \left\lceil\dfrac{N}{n}\right\rceil \qquad n = 1,\ldots, N$$
Consider the set of rational numbers $\left\{\dfrac{\lceil N/n\rceil}{n},\ n = 1,\ldots, N\right\}$ and write them from smallest to largest: $\left\{\dfrac{a_1}{b_1},\ldots,\dfrac{a_N}{b_N}\right\}$.
If $\dfrac{H}{W} \leq \dfrac{a_1}{b_1} = \dfrac{1}{N}$ then the optimal solution is:
$$C = N \qquad R = 1 \qquad S = H/N$$
If $\dfrac{a_n}{b_n} \leq \dfrac{H}{W} \leq \dfrac{a_{n+1}}{b_{n+1}}$ then the optimal solution is:
$$C = b_{n+1} \qquad R = a_{n+1} \qquad S = H/R $$
If $\dfrac{H}{W} \geq \dfrac{a_N}{b_N} = N$ then the optimal solution is:
$$ C = 1 \qquad R = N \qquad S = W/N$$