For how many [ordered pairs](https://artofproblemsolving.com/wiki/index.php/Ordered_pair) $(x,y)$ of [integers](https://artofproblemsolving.com/wiki/index.php/Integer) is it true that $0 < x < y < 10^6$ and that the [arithmetic mean](https://artofproblemsolving.com/wiki/index.php/Arithmetic_mean) of $x$ and $y$ is exactly $2$ more than the [geometric mean](https://artofproblemsolving.com/wiki/index.php/Geometric_mean) of $x$ and $y$?
Solution 1
\begin{eqnarray*} \frac{x+y}{2} &=& \sqrt{xy} + 2\\ x+y-4 &=& 2\sqrt{xy}\\ y - 2\sqrt{xy} + x &=& 4\\ \sqrt{y} - \sqrt{x} &=& \pm 2\end{eqnarray*}
Because $y > x$, we only consider $+2$.
For simplicity, we can count how many valid pairs of $(\sqrt{x},\sqrt{y})$ that satisfy our equation.
The maximum that $\sqrt{y}$ can be is $\sqrt{10^6} - 1 = 999$ because $\sqrt{y}$ must be an integer (this is because $\sqrt{y} - \sqrt{x} = 2$, an integer). Then $\sqrt{x} = 997$, and we continue this downward until $\sqrt{y} = 3$, in which case $\sqrt{x} = 1$. The number of pairs of $(\sqrt{x},\sqrt{y})$, and so $(x,y)$ is then $\boxed{997}$.

Solution 2
Let $a^2$ = $x$ and $b^2$ = $y$, where $a$ and $b$ are positive.
Then \[\frac{a^2 + b^2}{2} = \sqrt{{a^2}{b^2}} +2\]
\[a^2 + b^2 = 2ab + 4\]
\[(a-b)^2 = 4\]
\[(a-b) = \pm 2\]
This makes counting a lot easier since now we just have to find all pairs $(a,b)$ that differ by 2.

Because $\sqrt{10^6} = 10^3$, then we can use all positive integers less than 1000 for $a$ and $b$.

We know that because $x 0.\]
Therefore, there are only $\boxed{997}$ pairs of $(x,y).$
Solution by Williamgolly

Solution 5
First we see that our condition is $\frac{x+y}{2} = 2 + \sqrt{xy}$. Then we can see that $x+y = 4 + 2\sqrt{xy}$. From trying a simple example to figure out conditions for $x,y$, we want to find $x-y$ so we can isolate for $x$. From doing the example we can note that we can square both sides and subtract $4xy$: $(x-y)^2 = 16 + 16\sqrt{xy} \implies x-y = -2( \sqrt{1+\sqrt{xy}})$ (note it is negative because $y > x$. Clearly the square root must be an integer, so now let $\sqrt{xy} = a^2-1$. Thus $x-y = -2a$. Thus $x = 2 + \sqrt{xy} - a = 2 + a^2 - 1 -2a$. We can then find $y$, and use the quadratic formula on $x,y$ to ensure they are $>0$ and $<10^6$ respectively. Thus we get that $y$ can go up to 999 and $x$ can go down to $3$, leaving $997$ possibilities for $x,y$.