A Farmer has a flock of $n$ sheep, where $2000 \le n \le 2100$. The farmer puts some number of sheep into one barn and the rest of the sheep into a second barn. The farmer realizes that if she were to select two different sheeps at random from her flock, the probability that they are in different barns is exactly $1/2$. Determine the value of $n$.
Attempt:
If $k$ sheeps are placed in barn 1, and $n$ sheeps in barn 2, then the number of ways of selecting 2 sheeps from the flock such that tehy are in different barns is: $k (n-k)$. So the probability is $\frac{k(n-1)}{\binom{n}{2}}$, and it must have the property $$\frac{k(n-k)}{\binom{n}{2}} = \frac{1}{2}$$
I get a quadratic equation: $$ n^{2} - (1+4k)n + 4 k^{2} = 0$$
The solution is $$ n = \frac{1+4k \pm \sqrt{1+8k}}{2}$$
by trial I get that $k=1035$ satisfy an integer solution with $n=2025$. Is there better ways than trial?
You have $$n^2-(1+4k)n+4k^2=0 \implies (n-2k)^2=n.$$ Thus $n$ is a perfect square. The only perfect square in $[2000, 2100]$ is $2025$. Thus $n=2025$.