Solution (source code)

= Solution

For an electron of charge $-e$, <magnetic minimal coupling> gives $H=(\boldsymbol p+e\boldsymbol A)^2/(2m)$. In <Landau gauge>, $\boldsymbol A=(0,Bx,0)$, and fixing the conserved $p_y$ turns the Hamiltonian into a harmonic oscillator centered at $x=-p_y/(eB)$. The <Landau levels> are therefore
$$
\boxed{E_n=\hbar\omega_c(n+\tfrac12),\qquad\omega_c=eB/m,\qquad n=0,1,2,\ldots.}
$$
In a rectangle of dimensions $L_x,L_y$, consecutive momenta differ by $2\pi\hbar/L_y$, so consecutive oscillator centers differ by $2\pi\hbar/(eBL_y)$. Centers lying in the sample supply $eBA/(2\pi\hbar)$ orbitals per level. Neglecting the spin-field interaction leaves two degenerate spin states, rather than removing spin from Pauli counting. Thus each level holds $D=eBA/(\pi\hbar)$ electrons, to leading order for a large sample.

In the specified field range, $N\le D\le2N$. At zero temperature fill the lowest level with $D$ electrons and the next with $2N-D$. This <ground-state filling of two spin-degenerate Landau levels> gives
$$
\boxed{E_{\rm total}=\frac{\hbar eB}{m}(3N-D)=\frac{3N\hbar eB}{m}-\frac{e^2AB^2}{\pi m}.}
$$
At the lower endpoint the first two levels are exactly full; at the upper endpoint only the lowest level is full. Both give
$$
\boxed{E_{\rm endpoints}=\frac{2\pi\hbar^2N^2}{mA}.}
$$
Between them the total energy is a concave quadratic and is larger than this common endpoint value. Filling reorganizes as the magnetic degeneracy increases; ignoring spin splitting still requires retaining the twofold spin degeneracy in this calculation.