821. Find all natural numbers $p$ and $q$ for which the quadratic equation

$$
x^{2}-p q x+p+q=0
$$

has only integer roots.
Let's denote the integer roots of this equation as $x_{1}$ and $x_{2}$. Then, by Vieta's theorem:

$$
\left\{\begin{array}{l}
x_{1}+x_{2}=p q \\
x_{1} x_{2}=p+q
\end{array}\right.
$$

We have obtained a peculiar system of equations: the sum of two unknowns out of four equals the product of the other two, while the product of these two first unknowns equals the sum of the other two.

Since $p$ and $q$ are natural numbers, it follows from the system that the integers $x_{1}$ and $x_{2}$ are positive, and thus also natural.

To solve this system, we subtract its equations and transform the resulting equation as follows:

$$
\begin{gathered}
x_{1}+x_{2}-x_{1} x_{2}=p q-p-q, \quad\left(x_{1}+x_{2}-x_{1} x_{2}-1\right)+2=p q-p-q+1 \\
\left(x_{1}-1\right)\left(1-x_{2}\right)+2=(p-1)(q-1), \quad\left(x_{1}-1\right)\left(x_{2}-1\right)+(p-1)(q-1)=2
\end{gathered}
$$

Now let's think about the last equation: when is the sum of two non-negative integers equal to 2? In three cases:

1) $\left\{\begin{array}{l}\left(x_{1}-1\right)\left(x_{2}-1\right)=2, \\ (p-1)(q-1)=0,\end{array}\right.$
2) $\left\{\begin{array}{l}\left(x_{1}-1\right)\left(x_{2}-1\right)=1, \\ (p-1)(q-1)=1,\end{array}\right.$
3) $\left\{\begin{array}{l}\left(x_{1}-1\right)\left(x_{2}-1\right)=0, \\ (p-1)(q-1)=2 .\end{array}\right.$

We solve each of the resulting systems of equations, referring to the original system when necessary. Let's do this for the first system.

From the first equation of the first system, $x_{1}=3, x_{2}=2$ or $x_{1}=2, x_{2}=3$; from the second equation, $p=1$ or $q=1$.

If $p=1$, then from the first equation of the original system, we find $q: q=5$.

If $q=1$, then by the same method, we calculate $p: p=5$.

Answer: $p=1, q=5 ; p=5, q=1 ; p=q=2 ; p=2, q=3 ; p=3, q=2$.