How to calculate the total number of possible right angle triangles where the perimeter is given, and all sides are integers? I have been trying to find a formula to find the number of right angled triangles where all the sides are integers and the perimeter is given. I have seen the formula x3/((1-x2)(1-x3)(1-x4)), but that gives me the amount of possible triangles with that perimeter, not the amount of right - angled triangles. Does anyone know any formulas to find the amount of right angled, integer triangles of a given perimeter? Thanks in advance!
 A: To ensure the sides are integers, we use the famous parametrization: 
$$a=m^2-n^2$$
$$b=2mn$$
$$c=m^2+n^2$$
Then we have: ($p$ is perimeter)
$$p=a+b+c=2m^2+2mn=2m(m+n)$$
When $p$ is odd, no integer solutions for $m, n$ exist.
When $p=2ab$, the number of solutions is the number of $b$ such that $a<b<2a$, which is equivalent to the number of $k$ such that $k$ is a factor of $p$ and $\sqrt{p/2}<k<\sqrt{p}$.
For even $p \le 10$, there is no solution.
The first solution occurs at $p=12$, we have $m=2, n=1$, and $(a,b,c)=(3,4,5)$.
EDIT: I realized that a solution rarely exists. If you want to find some $p$ such that a solution exists, I suggest you substitute arbitrary values of $m,n$ into the formula $p=2m(m+n)$.
A: We know that $P=(m^2-n^2 )+2mn+(m^2+n^2 )=2m^2+2mn$
$$\text{We can find }(n,k)\text{ if we factor for  }n=\frac{P-2m^2}{2m}\text{ and let }m=1\text{ to }\biggl\lfloor\sqrt\frac{P}{2}\biggr\rfloor$$
One problem with lower values of $m$ is that it results in $n>m$ and yield $2{nd}$ quadrant triples and/or multiples such as $f(6,215)=(-46189,2580,46261)$. There is a minimum $m>1$ but it is not easy to figure out. The only solution at this time is to select integers where $n<m$ in the search.
$$\text{In the case of }(3,4,5)\text{ where }P=12, m_{min}=1; m_{max}=\biggl\lfloor\sqrt\frac{12}{2}\biggr\rfloor=2$$
We find that, from $m=1$ to $2$, only $2$ yields an integer for $n$ but this is good in that it shows $one$ triple $f(2,1)=(3,4,5)$ has a perimeter of $12$. (No triples will be found for $P=13$, etc.)
Here we have a known perimeter: $P(51,1300,1301)= 2652$ and wish to find its match, if any.
$$m_{max}=\biggl\lfloor\sqrt\frac{2652}{2}\biggr\rfloor=36$$
Searching from $1$ to $36$, we find integers $(m>n)$ only when $m=26$ and $m=34$ and we find:
$$(m,n)=(26,25)\Rightarrow A=26^2-25^2=51\quad B=2*26*25=1300\quad C=26^2+25^2)=1301 $$
$$(m,n)=(34,5)\Rightarrow A=34^2-5^2=1131\quad B=2*34*5=340\quad C=34^2+5^2)=1181 $$
