Pythagorean Triplets & Prime Factors

Read this knowing that I have no mathematics background whatsoever.

I was solving a specific programming problem that required knowledge of Pythagorean triplets, which is something that I hadn't really worked with before. Anyway, I'm curious if there is an existing proof for this:

The Wikipedia article on Pythagorean triplet functions states that for any positive integer greater than $a = 3$, triplets can be generated with the following formulas:

If a is odd: $b = \frac{a^2}{2} - \frac{1}{2}$ and $c = b + 1$

If b is even: $b = \frac{a^2}{4} - 1$ and $c = b + 2$

However, in looking at the output of a Pythagorean triplet generator I created in Ruby, I noticed a pattern which seemed to say that the above functions actually point to a more generic one:

For any positive integer $a$, where $p$ is any prime factor of $a$ greater than $2$:

$$b = \frac{a^2}{2(\frac{a}{p})} - \frac{\frac{a}{p}}{2}$$ and $$c = b + \frac{a}{p}$$

For example, let's say that $a=99$ and that $p=11$.

$$b = \frac{99^2}{2(\frac{99}{11})} - \frac{\frac{99}{11}}{2} = 540$$ $$c = 540 + \frac{99}{11} = 549$$

Finally:

$$99^2 + 540^2 = 549^2$$

Or with the prime number $a=48611$ and $p=48611$, you end up with:

$$48611^2 + 1181514660^2 = 1181514661^2$$

This would also imply that for any base $a$, there are at least the same number of Pythagorean triplets that there are of prime factors of $a$ greater than 2, and that likewise, any prime number can be the $a$ of only a single pythagorean triplet.

Edit

As @ThomasAndrews pointed out and I realized, $p$ need not be prime.

• You don't need $p$ to be prime - you can make it any factor of $a$. If $p\neq a$, though, the $b$ you get this way is not (often) relatively prime to $a$, so it is not considered a "primitive" pythagorean triple. – Thomas Andrews Jan 19 '12 at 19:36
• @ThomasAndrews Thanks, I just had that thought a minute ago. Is there a name or some sort of basis for this technique? – clem Jan 19 '12 at 19:38
• Which technique? In the above examples, you've just multipled an example with $a=11$ and $a=33$ by $9$ and $3$, respectively, to get examples with $a=99$. I suppose you could call that scaling. The original formula is not meant to generate all triples, anyway, just a quick way to find one triple which contains a particular value of $a$. – Thomas Andrews Jan 19 '12 at 19:46
• I just used $99$ again being lazy, but it could have by any positive integer. – clem Jan 19 '12 at 19:50
• My point is, starting with $a=11$, and using the original formula, you get $b=60$ and $c=61$. And the triple you got is just $9$ times this triple $(11,60,61)$. Similarly, the triple you get starting from $a=3$ is $(3,4,5)$, and your triple $(99,132,165)$ is just 33 times that original triple. So these "new" triples aren't very new. – Thomas Andrews Jan 19 '12 at 19:58

Your formula does yield "new" triples, but they are not primitive triples, just multiples of the triples that come from the first formula. Specifically, if $p$ is a factor of $a$, then using the original formula for $p$ yields the triple $(p,\frac{p^2-1}2,\frac{p^2+1}2)$. Multiplying the triple by $\frac a p$ gives $(a,b,c)$ with $b=\frac{pa-\frac{a}{p}}2$. This is the same as your formula.
Note that the original formula doesn't even necessarily give you a primitive triple when $a$ is even. For example, when $a=6$, $b=8.$ In general, the formula only gives you a primitive triple for even $a$ when $4|a$.
There is a relationship between prime factorizations of $a$ and the set of primitive triples that contain $a>1$. Specifically, let $z(n)$ be the number of distinct prime divisors of $n$. Then, for fixed $a>1$, the number of primitive solutions to $a^2+b^2=c^2$ with $b,c>0$ is $2^{z(a)-1}$ if $a$ is odd or $4|a$, and $0$ otherwise.
This can be seen as a result of the fact that primitive triples can be written as $(u^2-v^2,2uv,u^2+v^2)$ where $(u,v)=1$ and $u,v$ are not both odd.
In any event, the point of the formula you found on Wikipedia was not to be exhaustive, but rather to quickly show that any $a$ can be found in some non-trivial triple $(a,b,c)$.
• Thanks! This is exactly the type of explanation I was looking for. The specific problem I was working on involves finding the triplet for which $a + b + c = 1000$, but seeing this pattern, I wasn't sure what I was looking at and was curious. For someone with only a high-school level mathematics education but lots of programming experience, this was a great explanation. – clem Jan 19 '12 at 23:55
• @clem: Had a typo. For triples such that a+b+c=1000$, use the representation$a=k(2mn)$,$b=k(m2−n2)$,$c=k(m2+n2)$where$m>n$,$m$and$n$are relatively prime and of opposite parity. Then$a+b+c=k(2m)(m+n)$. quickly one finds from the prime factorization of$1000\$ that there is only one triple. For numbers with a more complicated prime factorization, analysis is possible but more complicated. – André Nicolas Jan 20 '12 at 7:07