OFFSET
1,4
COMMENTS
The PARI script is direct and very fast for m = x,y values but slows in the trial routine for m = z. We save some time for m even allowing the testing of only even values of y.
FORMULA
Consider Pythagorean triples x^2 + y^2 = z^2. We seek to find the total number of instances of an integer m being x or y or z. The solution for x or y is straightforward by considering appropriate lesser and greater pairwise factors, L, G of m^2 in z^2 - y^2 = (z-y)(z+y) = m^2. Then solve for z and y with the relations, z-y = L z+y = G 2z = L+G, z = (L+G)/2 where L and G are both even if m is even or both odd if m is odd. The number of L factors < m is the number of instances of x or y. The count of instances z=m is solved by trial on x^2 = m^2 - y^2.
EXAMPLE
For m=30 there are 5 Pythagorean triples that have a 30:
30, 224, 226
30, 72, 78
30, 40, 50
30, 16, 34
18, 24, 30
PROG
(PARI)
\\ instances of m in Pythagorean triples using a direct method for x, y
pythm3(m) = { local(m2, ln, j, j2=0, d, d2, q2, q, a, b, x, x1, x2, xx, y, y2, z, c, c2, r, f, str, stp); d=divisors(m^2); /* get the divisors of m^2 */ ln=length(d)-1; d2=q2=vector(ln); m2=m^2; if(m%2, r=1, r=0); for(j=1, ln, /* save only the both even r=0, both odd r=1 */ if(d[j]%2==r, if(m2/d[j]%2==r, j2++; d2[j2]=d[j]; q2[j2]=m2/d[j]; /* save m/factor to solve (z-y)(z+y) = m^2 */ ) ) ); x2=y2 = vector(20); for(j=1, j2, z=(d2[j] + q2[j])/2; y= z - d2[j]; if(y>0, c++; ) ); if(m%2==0, start=2; step=2, start=1; step=1); forstep(y=start, m-1, step, /* esolve when z is m */ x1 = (m2-y^2); if(issquare(x1), c2++; x2[c2]=floor(sqrt(x1)); /* save to later mask dupes */ y2[c2]=y; ) ); for(x=1, c2, /* mask the dupes routine */ for(y=x, c2, if(x2[x]==y2[y], ) ) ); return(c+c2/2) /* print total */}
for(k=1, 400, if(isprime(k)==0, print1(pythm3(k)", ")))
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Cino Hilliard, Apr 18 2005
STATUS
approved