13.39 Let $M$ be a point on the plane with coordinates $(p \times 1994, 7p \times 1994)$, where $p$ is a prime number. Find the number of right triangles that satisfy the following conditions:
(1) The three vertices of the triangle are all integer points, and $M$ is the right-angle vertex;
(2) The incenter of the triangle is the origin.
(9th China High School Mathematics Winter Camp, 1994)
[Solution] Connect the origin $O$ and point $M$, and take the midpoint $I(p \times 997, 7p \times 997)$ of the line segment $OM$. Perform a central symmetry about point $I$, transforming point $(x, y)$ into point $(p \times 1994 - x, 7p \times 1994 - y)$. Thus, a right-angled triangle that satisfies the conditions is transformed into a congruent right-angled triangle with integer coordinates, with the incenter at point $M$ and the right angle at the origin. Therefore, the number of right-angled triangles with integer coordinates that satisfy the conditions can be considered by only looking at the case where the right angle is at the origin and the incenter is at point $M$.

Consider a right-angled triangle $\triangle OAB$ with integer coordinates that satisfies the above conditions.
Let $\angle xOA = \alpha$, $\angle xOM = \beta$. Then $\alpha + \frac{\pi}{4} = \beta$.
From the given conditions, $\operatorname{tg} \beta = 7$.
$$
\operatorname{tg} \alpha = \operatorname{tg}\left(\beta - \frac{\pi}{4}\right) = \frac{\operatorname{tg} \beta - \operatorname{tg} \frac{\pi}{4}}{1 + \operatorname{tg} \beta \operatorname{tg} \frac{\pi}{4}} = \frac{3}{4}.
$$

Thus, the coordinates of any point on the leg $OA$ can be written as $(4t, 3t)$.
Since $A$ is an integer point, if $A(4t, 3t), t \in \mathbb{N}$, then $OA = 5t$.
From $\angle yOB = \alpha$, the coordinates of point $B$ are $\left(-3t_0, 4t_0\right), t_0 \in \mathbb{N}, OB = 5t_0$.
The inradius of the right-angled triangle is $r = \frac{\sqrt{2}}{2} OM = 5p \times 1994$.
Let $OA = 2r + p_0$, $OB = 2r + q_0$,
Since $OA$, $OB$, and $r$ are all multiples of 5, then $p_0$ and $q_0$ are also multiples of 5.
$$
AB = OA + OB - 2r = 2r + p_0 + q_0.
$$

By the Pythagorean theorem, $AB^2 = OA^2 + OB^2$, i.e.,
$$
\left(2r + p_0 + q_0\right)^2 = \left(2r + p_0\right)^2 + \left(2r + q_0\right)^2,
$$

then $p_0 q_0 = 2r^2$,
i.e., $p_0 q_0 = 2 \cdot 5^2 \cdot 1994^2 \cdot p^2$.
Since $\frac{p_0}{5}$ and $\frac{q_0}{5}$ are natural numbers, we have
$$
\frac{p_0}{5} \cdot \frac{q_0}{5} = 2^3 \times 977^2 \times p^2.
$$

When $p \neq 2$ and $p \neq 997$,
$$
\left\{\begin{array}{l}
\frac{p_0}{5} = 2^i \times 997^j \times p^k, \\
\frac{q_0}{5} = 2^{3-i} \times 997^{2-j} \times p^{2-k}.
\end{array}\right.
$$

where $i = 0, 1, 2, 3$, $j = 0, 1, 2$, $k = 0, 1, 2$.
Thus, $\left(\frac{p_0}{5}, \frac{q_0}{5}\right)$ has $4 \times 3 \times 3 = 36$ different ordered solutions.
When $p = 2$, we have
$$
\left\{\begin{array}{l}
\frac{p_0}{5} = 2^i \times 997^j, \\
\frac{q_0}{5} = 2^{5-i} \times 997^{2-j}.
\end{array}\right.
$$

where $i = 0, 1, 2, 3, 4, 5$, $j = 0, 1, 2$.
Thus, $\left(\frac{p_0}{5}, \frac{q_0}{5}\right)$ has $6 \times 3 = 18$ different ordered solutions.
When $p = 997$, we have
$$
\left\{\begin{array}{l}
\frac{p_0}{5} = 2^i \times 997^j, \\
\frac{q_0}{5} = 2^{3-i} \times 997^{4-j}.
\end{array}\right.
$$

where $i = 0, 1, 2, 3$, $j = 0, 1, 2, 3, 4$.
Thus, $\left(\frac{p_0}{5}, \frac{q_0}{5}\right)$ has $4 \times 5 = 20$ different ordered solutions.
Therefore, the number of right-angled triangles is:
$$
S = \left\{\begin{array}{ll}
36, & \text{when } p \neq 2 \text{ and } p \neq 997, \\
18, & \text{when } p = 2, \\
20, & \text{when } p = 997.
\end{array}\right.
$$