5. Find all triples of distinct prime numbers $p, q, r$ satisfying the following conditions:

$$
\begin{array}{l|l}
p & q+r, \\
q & \mid r+2 p, \\
r & \mid p+3 q .
\end{array}
$$

(M. Panák)
Solution. Let's look for triples $p, q, r$ based on which of these three numbers is the largest:

$\triangleright$ The largest is $p$. Then from the condition $p \mid q+r$ and the inequality $q+r<2 p$ it follows that $q+r=p$. From the second condition, we then get $q \mid r+2 p=3 r+2 q$, i.e., $q \mid 3 r$, which, given the distinctness of the primes, means that $q=3$. Thus, $p=r+3$ and the last condition says that $r \mid r+12$, or $r \mid 12$, so $r=2$ (the primes must be distinct). Therefore, $p=5$. This triple indeed satisfies the conditions of the problem.

$\triangleright$ The largest is $q$. Then the condition $q \mid r+2 p$ and the inequality $r+2 p<3 q$ give $r+2 p=q$ or $r+2 p=2 q$.

If $2 q=r+2 p$, then $r$ must be even. Thus, $r=2$ and from the equality $2 q=2+2 p$ it follows that $q=p+1$, which is not possible for primes $p, q$ greater than $r=2$.

If $q=r+2 p$, the first condition says that $p \mid 2 r+2 p$, so $p \mid 2 r$, hence $p=2$. The last condition then gives $r \mid p+3 q=3 r+7 p=3 r+14$, so $r \mid 14$, thus $r=7$. Then $q=r+2 p=11$. This triple also satisfies the problem's conditions.

$\triangleright$ The largest is $r$. Then we compare the condition $r \mid p+3 q$ and the inequality $p+3 q<4 r$.

If $p+3 q=3 r$, then $p=3(r-q)$, so $p=3, r-q=1$, thus $r=3$ and $q=2$, which are not three distinct primes.

If $p+3 q=2 r$, we get from the first condition $p \mid 2(q+r)=p+5 q$, so $p \mid 5 q$ and $p=5$. The second condition then gives $q \mid 2(r+2 p)=2 r+20=3 q+25$, so $q=5$, and the resulting triple does not consist of distinct primes.

Finally, let $p+3 q=r$. The first condition then gives $p \mid p+4 q$, so $p \mid 4 q$ and $p=2$. The second condition then says that $q \mid r+2 p=3 q+6$, so $q \mid 6$ and $q=3$, since $q \neq p=2$. Then $r=p+3 q=11$. This triple also satisfies the problem's conditions.

The solutions to the problem are three triples of primes $(p, q, r)$, namely $(5,3,2),(2,11,7)$ and $(2,3,11)$.