Example 4 (CMO-9 Test) 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:
(A)
(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 of the coordinates.
Solve: Connect the origin $O$ and point $M$, take the midpoint $I(p \times 997,7 p \times 997)$ of segment $O M$, and perform a central symmetry about point $I$, i.e., transform point $(x, y)$ to point $(p \times 1994- x, 7 p \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 becoming point $M$ and the right-angle vertex becoming 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 vertex is at the origin and the incenter is at point $M$.
Simplified:
Consider a right-angled triangle $\triangle O A B$ with integer coordinates that satisfies the above conditions.

Let $\angle x O A=\alpha, \angle x O M=\beta$, then $\alpha+\frac{\pi}{4}=\beta$.
From the given conditions, we know $\tan \beta=7$,
$$
\tan \alpha=\tan \left(\beta-\frac{\pi}{4}\right)=\frac{\tan \beta-\tan \frac{\pi}{4}}{1+\tan \beta \tan \frac{\pi}{4}}=\frac{3}{4} .
$$

Thus, the coordinates of any point on the leg $O A$ can be written as $(4 t, 3 t)$.
Since $A$ is an integer point, if $A(4 t, 3 t), t \in \mathbf{N}$, then $O A=5 t$.
From $\angle y O B=\alpha$, we know that the coordinates of point $B$ are $\left(-3 t_{0}, 4 t_{0}\right), t_{0} \in \mathbf{N}, O B=5 t_{0}$.
The inradius of the right-angled triangle is $r=\frac{\sqrt{2}}{2} O M=5 p \times 1994$.
Let $O A=2 r+p_{0}, O B=2 r+q_{0}$.
Since $O A, O B, r$ are all multiples of 5, then $p_{0}, q_{0}$ are also multiples of 5.
$$
A B=O A+O B-2 r=2 r+p_{0}+q_{0} \text {. }
$$

By the Pythagorean theorem, $A B^{2}=O A^{2}+O B^{2}$, i.e.,
$\left(2 r+p_{0}+q_{0}\right)^{2}=\left(2 r+p_{0}\right)^{2}+\left(2 r+q_{0}\right)^{2}$, then
$p_{0} q_{0}=2 r^{2}$, i.e.,
$p_{0} q_{0}=2 \cdot 5^{2} \cdot 1994^{2} \cdot p^{2}$.
Since $\frac{p_{0}}{5}, \frac{q_{0}}{5}$ are both natural numbers, we get
$\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.
$$
Olympic
Mathematics
Number
Theory
Problem
Here $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.
From the above, the number of right-angled triangles:
$S=\left\{\begin{array}{l}36, \text { when } p \neq 2 \text { and } p \neq 997 \text {, } \\ 18, \text { when } p=2 \text {, } \\ 20, \text { when } p=997 \text { . }\end{array}\right.$