Pythagorean triples: Difference between revisions
Content deleted Content added
Walterpachl (talk | contribs) |
|||
Line 1,286: | Line 1,286: | ||
This version is reasonably efficient and can handle inputs like a million quickly. |
This version is reasonably efficient and can handle inputs like a million quickly. |
||
<lang parigp>do(lim)={ |
<lang parigp>do(lim)={ |
||
my(prim,total); |
my(prim,total,P); |
||
lim\=1; |
lim\=1; |
||
for(m=2,sqrtint(lim |
for(m=2,sqrtint(lim\2), |
||
forstep(n=1+m%2,min(sqrtint(lim-m^2),m-1),2, |
forstep(n=1+m%2,min(sqrtint(lim-m^2),m-1),2, |
||
P=2*m*(m+n); |
|||
if(gcd(m,n)==1 && P<=lim, |
|||
prim++; |
prim++; |
||
total+=lim\ |
total+=lim\P |
||
) |
) |
||
) |
) |