Pythagorean triples/Java/Brute force primitives: Difference between revisions

m
a*b = 0 (mod 12) for all triples, very very slight speedup, checking that a*b*c = 0 (mod 60) actually slowed it down
m (Moved the LIMIT declaration but forgot to take the comment with it)
m (a*b = 0 (mod 12) for all triples, very very slight speedup, checking that a*b*c = 0 (mod 60) actually slowed it down)
Line 9:
import java.util.TreeSet;
import static java.math.BigInteger.ONE*;
 
public class PythTrip2{
public static final BigInteger TWO = BigInteger.valueOf(2),
B7 = BigInteger.valueOf(7), //B7...B191 are used for skipping non-square "a^2 + b^2"s
B12 = BigInteger.valueOf(12),
B31 = BigInteger.valueOf(31),
B127 = BigInteger.valueOf(127),
Line 80 ⟶ 81:
for(BigInteger b = a.add(ONE);
b.compareTo(peri2) < 0; b = b.add(TWO)){
BigInteger bb = b.multiply(b);
//if a^2 + b^2 is not a perfect square then don't even test for c's
BigInteger aabb = aa.add(bbb.multiply(b));
if((aabb.and(B7).intValue() != 1) &&
(aabb.and(B31).intValue() != 4) &&
Line 88:
(aabb.and(B191).intValue() != 0)) continue;
BigInteger ab = a.add(b);
if(a.multiply(b).mod(B12).compareTo(ZERO) != 0) continue;
 
for(BigInteger c = b.add(b.and(ONE).equals(ONE)? TWO:ONE);
Anonymous user