4. (15 points) If there exists a right-angled triangle with all sides of integer length, and the ratio $k$ of the square of its perimeter to its area is an integer, then this integer $k$ is called a "triangle number". Find all such triangle numbers.

Translate the above text into English, please retain the original text's line breaks and format, and output the translation result directly.
4. Let the three sides of a right-angled triangle be \(m^{2}-n^{2}\), \(2 m n\), and \(m^{2}+n^{2}\) \((m, n \in \mathbf{N}_{+}, m > n)\).
Assume \(m\) and \(n\) are coprime.
Then the perimeter \(l = 2 m^{2} + 2 m n\),
and the area \(S = m n (m^{2} - n^{2})\).
Thus, \(k = \frac{l^{2}}{S} = \frac{4 m (m + n)}{n (m - n)}\).
Since \((m, n) = 1\), it follows that \((n, m + n) = 1\) and \(n \mid 4\).
Therefore, \(n = 1, 2, 4\).
(1) When \(n = 1\),
$$
k = \frac{4 m (m + 1)}{m - 1} = 4 m + 8 + \frac{8}{m - 1}.
$$

Then \((m - 1) \mid 8 \Rightarrow m = 2, 3, 5, 9\).
Thus, the values of \(k\) are 24, 30, 45.
(2) When \(n = 2\),
$$
k = \frac{4 m (m + 2)}{2 (m - 2)} = 2 m + 8 + \frac{16}{m - 2}.
$$

Then \((m - 2) \mid 16\).
So \(m\) can be 3, 4, 6, 10, 18.
But \((m, n) = 1\), so \(m = 3\), and the value of \(k\) is 30.
(3) When \(n = 4\),
$$
k = \frac{4 m (m + 4)}{4 (m - 4)} = m + 8 + \frac{32}{m - 4}.
$$

Then \((m - 4) \mid 32\).
But \((m, n) = 1\), so \(m = 5\), and the value of \(k\) is 45.
In summary, all possible values of \(k\) are 24, 30, 45.