Good morning, I'm new here and I bring a small problem. I'm having trouble develop efficient an algorithm for the following problem: I need to find combinations of three positive numbers x, y and z so that x + y, x - y, y + z, y - z, x + z and x - z are perfect squares. The issue is to develop an algorithm that finds all combinations of x, y and z between 1 and 2,000,000.
Currently I use a for
within a for
that certainly will not end before I have my grandchildren.
The basic idea to begin with a substitution, like:
u = x + y
v = x - y
w = y + z
Then x + y, x - y, y + z, y - z, x + z and x - z becomes
u, v, w, u - v - w, v + w, u - w [all have to be squares]
Then with another substitution, u = a², v = b², w = c², you get:
a², b², c², a² - b² - c², b² + c², a² - c² [all have to be squares]
now you can enumerate all a, b, c-s which may already be fast enough.
Further ideas could be to first enumerate all b², c², b²+c² using Pythagorean triples (by substituting it to m and n, enumerating all coprime (m,n) and then using Euclid formula) and then find for given (b,c) the as in a similar way (e.g. change a² - c² = x² to a² = x² + c² and use the triples again).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With