4. In $\triangle A B C$, $\angle B C A=90^{\circ}$, a perpendicular $C D \perp A B$ is drawn from $C$ intersecting $A B$ at $D$. Suppose the side lengths of $\triangle A B C$ are all integers, and $B D=29^{3}, \cos B=\frac{m}{n}$, where $m$ and $n$ are coprime positive integers. Then $m+n=$ $\qquad$
4. 450 .

Let the three sides of $\triangle ABC$ be $a, b, c$. It is easy to prove that $BC^2 = BD \cdot BA$. Therefore, $a^2 = 29^3 c$.
Since 29 is a prime number, $29^2 \mid a$.
Let $a = 29^2 k$ ($k$ is a positive integer), then $c = 29 k^2$.
Since $b = \sqrt{c^2 - a^2} = 29 k \sqrt{k^2 - 29^2}$ is an integer, we know that $k^2 - 29^2 = t^2$ ($t$ is a positive integer).
$$
\therefore (k-t)(k+t) = 29^2 \text{. }
$$

Solving this, we get $k = 421$.
$$
\therefore BC = 29^2 \times 421 \text{. }
$$

Thus, $\cos B = \frac{BD}{BC} = \frac{29}{421}$.
$$
\therefore m+n = 450 \text{. }
$$