We have the following relations:
$$P=a+b+c,\quad 2A=ab,\quad a^2+b^2=c^2$$
In fact, there is one more that is implicit: the triangle inequality $a+b>c$ (which follows from $a^2+b^2=c^2$). We wish to relate the first and second relations, and so after staring at the problem for a while we realize the correct course of action is to multiply $P$ by $a+b-c$ (the latter guaranteed to be positive by the triangle inequality). This gives:
$$\begin{align}P(a+b-c)&=(a+b+c)(a+b-c)=(a+b)^2-c^2\\
&=a^2+b^2+2ab-c^2=2ab=4A
\end{align}$$
Hence in general for a right triangle we have $k=A/P=(a+b-c)/4$, so the question boils down to when the difference between the sum of the lengths of the legs and the length of the hypothenuse divides or is divisible by $4$, for a right triangle with integer side-lengths.
Here we actually need to generate pythagorean triples $(a,b,c)$ such that $a,b,c$ are integers and $a^2+b^2=c^2$; the wikipedia page here gives a good picture of Euclid's formula that I recommend thinking through. Euclid's formula is the following:
$$a=m^2-n^2,\quad b=2mn\quad c=m^2+n^2$$ for integers $m>n$.
Then the quantity $a+b-c$ is $m^2-n^2+2mn-m^2-n^2=2n(m-n)$, so $A/P=k=n(m-n)/2$. The options are now that either $2$ divides $n$ or $2$ divides $m-n$, so we either have $n=2d$ and $m=k/d+2d$ or $n=d$ and $m=2(k/d)+d$ for divisors $d$ of $k$.
(to get $P/A=k$ we need $2n(m-n)$ to divide $4$, so $n(m-n)$ must divide $2$, thus $n=1$, $m=2$, $n=1$, $m=3$, and $n=2$, $m=3$ are the only solutions, giving us $(3,4,5)$, $(8,6,10)$, $(5,12,13)$ with $k=2,1,2$ being the only possibilities).
Just to show that Heron's formula isn't so bad ...
In
$$\text{area}^2 = \frac{1}{16}(a+b+c)(-a+b+c)(a-b+c)(a+b-c)$$
you know $c=21$ and $a+b+c=54$, so that $b=33-a$. So, the above becomes
$$\begin{align}
\text{area}^2 &= \frac{1}{16}(54)(54-2a)(2a-12)(12) \\[4pt]
&= 2\cdot 3^4 \cdot (27-a)(a-6)
\end{align}$$
Thus, $a$ is somewhere between $6$ and $27$. Since the right-hand side needs to be a perfect square, the factors $(27-a)$ and $(a-6)$ need to contribute an odd number of $2$s, and an even number of any other prime, to the factorization. You can tick through cases pretty quickly, using the latter fact to instantly weed-out cases with obvious singleton prime factors before expending any real mental energy counting other primes:
$$\begin{array}{rccll}
a & (27-a) & ( a - 6 ) & & \\
7 & 20 & 1 & \text{single } 5\\
8 & 19 & 2 & \text{single } 19 \\
9 & 18 & 3 & - & 3^\text{odd} \to \text{nope!}\\
10 & 17 & 4 & \text{single } 17\\
11 & 16 & 5 & \text{single } 5\\
12 & 15 & 6 & \text{single } 5 \\
\color{red}{13} & \color{red}{14} & \color{red}{7} & \color{red}{-} & \color{red}{2^\text{odd} \cdot 7^\text{even} \to \text{yes!}} \\
14 & 13 & 8 & \text{single } 13\\
15 & 12 & 9 & - & 3^\text{odd}, 2^\text{even} \to \text{nope!}\\
16 & 11 & 10 & \text{single } 11 \\
17 \dots 26 & - & - & \text{don't need to check} & \text{(why?)} \\
\end{array}$$
Therefore, the other sides have length $13$ and $33-13=20$. $\square$
Best Answer
The equation,
$$wxyz=(w+x+y+z)^2\tag{1}$$
can be solved as a quadratic in $z$,
$$(w + x + y)^2 + \big(2(w + x + y) - w x y\big) z + z^2=0\tag{2}$$
Its discriminant is $wxy(wxy-4\big(w+x+y)\big)$ and must be made a square. It can be shown an initial solution $a,x,y$ can generate an infinite more. Define,
$$axy(axy-4\big(a+x+y)\big)=c^2\tag{3}$$
$$a^2xy(xy-4) =d\tag{4}$$
then a family of solutions to (2) can be given as,
$$w =\frac{a(p-cq)^2}{p^2-dq^2}\tag{5}$$
$$z =-(w+x+y)+\frac{1}{2}\left(wxy\pm\frac{(p-cq)(cp-dq)}{p^2-dq^2}\right)\tag{6}$$
for arbitrary $p,q$. If we want integers, then one can solve the Pell equation $p^2-dq^2=1$. Some examples are,
$$w,x,y = 4,\;4,\;4(p-q)^2;\;\;z=4(p+q)^2\;\text{or}\;\;4(3p-5q)^2,\;\;\text{where}\;p^2-3q^2=1\tag{7}$$
or,
$$w,x,y = 3,\;3,\;6(p-q)^2;\;\;z=6(p+q)^2\;\text{or}\;\;24(p-2q)^2,\;\;\text{where}\;p^2-5q^2=1\tag{8}$$
and so on.