31. How many ordered pairs of integers $(x, y)$ satisfy the equation
$$
x^{2}+y^{2}=2(x+y)+x y ?
$$
31. Ans: 6
We can rearrange the equation to get
$$
x^{2}-x(2+y)+y^{2}-2 y=0 .
$$

As a quadratic equation in the variable $x$, the discriminant of the above equation is given by
$$
\text { Discriminant }=(2+y)^{2}-4(1)\left(y^{2}-2 y\right)=4+12 y-3 y^{2}=16-3(y-2)^{2} .
$$

Since $x$ is an integer, the discriminant must be a perfect square and thus it is non-negative. Hence,
$$
16-3(y-2)^{2} \geq 0 \Longrightarrow(y-2)^{2} \leq \frac{16}{3} \Longrightarrow|y-2|<\frac{4}{\sqrt{3}}<3 .
$$

Since $y$ is an integer, it follows that its only possible values are given by $y=$ $0,1,2,3,4$. When $y=1,3$, the discrimant is 12 , which is not a perfect square. Thus, $y=0,2,4$.
When $y=0$, we have $x^{2}-2 x=0 \Rightarrow x=0,2$.
When $y=2$, we have $x^{2}-4 x=0 \Longrightarrow x=0,4$.
When $y=4$, we have $x^{2}-6 x+8=0 \Longrightarrow x=2,4$.
Thus, there are 6 solutions, namely $(0,0),(2,0),(0,2),(4,2),(2,4),(4,4)$.