# Project Euler #142: Perfect Square Collection

# Project Euler #142: Perfect Square Collection

+ 1 comment I understand the problem clearly. But i dont have any idea how to generate triplets.

+ 1 comment Not a so easy problem. I found 10560 triples for x under 10^12 but it takes 47s to my python program to find them which is quick enough to pass the first 7 test cases but not the last one.

My program is based on pythagorean triples :

x+y = a² x-y = b² x+z = c² x-z = d² y+z = e² y-z = f² => a² = c² + f² with c>f a² = d² + e² with c>e and (c+d)%2 = 0 c²-e² = b²

So I generate all pythagorean triples with hypotenuse = a in ascending order then for each combinations of pythagorean triples with same a, I test all the 3 left constraints (c>e, (c+d)%2 = 0 and c²-e² = b²).

I have not much idea how to improve that. Can we skip some pythagorean triplets? Can we have some constraint on d and e to avoid to test twice with them reversed?

I found some other way to solve that but did not implement it yet : https://sites.google.com/site/tpiezas/0020. What did you implemented?

+ 0 comments I am bit confused with the problem statements.

+ 0 comments Passed all test cases except #7 and #8.. Anybody have any tips about why this might be? To me my algorithm works when N>=3000, but apparently not?

It's not a timeout issue as I'm returning answers fast.

+ 1 comment error: no suitable method found for valueOf(BigInteger)

for (BigInteger x =BigInteger.valueOf(1234567890);x.compareTo(BigInteger.ZERO) > 0;x=x.subtract(BigInteger.ONE)) { for (BigInteger y =BigInteger.valueOf(x);y.compareTo(BigInteger.ZERO) > 0;y = y.subtract(BigInteger.ONE)) { for (BigInteger z = BigInteger.valueOf(y); z.compareTo(BigInteger.ZERO) > 0; z = z.subtract(BigInteger.ONE))

pls help!!!

Sort 12 Discussions, By:

Please Login in order to post a comment