As shown in one answer and
another answer,
The maximum number of squares of edge-length $E$ that can fit in a rectangle
of width $W$ and height $H$ is
$$ \left\lfloor\frac WE\right\rfloor \times \left\lfloor\frac HE\right\rfloor, $$
and one way to fit that number of squares in the rectangle is to construct a grid of squares $\left\lfloor\frac WE\right\rfloor$ squares wide by
$\left\lfloor\frac HE\right\rfloor$ squares high in the lower left corner of the rectangle.
The proofs do not actually require any of these numbers to be an integer, but you may assume $E$ is an integer for the purpose of your question.
As mentioned in a comment (which could have been an answer), the edge length $E$
that you want is the largest integer such that
$\left\lfloor\frac WE\right\rfloor \times \left\lfloor\frac HE\right\rfloor \geq n.$
I do not see an obvious way to find the correct value of $E$ without allowing for some trial and error. But you can estimate the value to get the answer relatively quickly.
Let
$$ s = \sqrt{\frac{W\times H}{n}}. $$
Then $s$ is an upper bound on the possible length $E$; you cannot fit $n$ squares of side greater than $s$ in the rectangle, because the squares would have a greater area than the rectangle. Therefore $E \leq s.$
But we can do better than that, because we need whole rows and columns of squares inside the rectangle. If $s$ does not evenly divide both $W$ and $H$, the largest grid of whole squares of edge-length $s$ we can fit in the rectangle will not be enough squares.
The only way to get more squares is to reduce the edge length until we can fit at least one more row or one more column in the rectangle.
That is, we need either $\left\lceil H/s \right\rceil$ rows
or $\left\lceil W/s \right\rceil$ columns. So we conclude that
$$ E \leq
\max\left\{\frac{W}{\left\lceil \frac Ws \right\rceil},
\frac{H}{\left\lceil \frac Hs \right\rceil}\right\}
= \max\left\{\frac{W}{\left\lceil \sqrt{\frac{n\times W}{H}}\, \right\rceil},
\frac{H}{\left\lceil \sqrt{\frac{n\times H}{W}}\, \right\rceil}\right\}. $$
We can start at the largest integer less than or equal to the expression on the right, and if that value of $E$ is too large, try smaller values.
Example: Let $W=945$, $H=447$, and $n=34.$ Then
\begin{align}
\sqrt{\frac{n\times W}{H}} &\approx 8.48, \\
\sqrt{\frac{n\times H}{W}} &\approx 4.01, \\
\frac{W}{\left\lceil \sqrt{\frac{n\times W}{H}}\, \right\rceil}
&= \frac{945}{9} = 105, \\
\frac{H}{\left\lceil \sqrt{\frac{n\times H}{W}}\, \right\rceil}
&= \frac{447}{5} = 89.4. \\
\end{align}
The greater of the values $105$ and $89.4$ is $105.$
Trying $E = 105,$ we find we can fit $4$ rows by $9$ columns of squares of that size in the rectangle, and $4 \times 9 = 36,$ so we can omit two squares from the grid and we have fit $n=34$ squares in the rectangle.
Any larger square can fit at most $4$ rows by $8$ columns, which gives only $32$ squares, so $E=105$ is the correct answer.