简体   繁体   中英

Combinations of three positive numbers x, y, z so that x + y, x - y, y + z, y - z, x + z and x - z are perfect squares

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, cs 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 (eg change a² - c² = x² to a² = x² + c² and use the triples again).

Extending BeniBela's answer ,

x + y = (x - z) + (y + z)
x + y = (x + z) + (y - z)

So, triplets are valid only if the hypotenuse can be represented in two different forms. Further filtering can be done by observing that (x - z) and (x + z) also form the hypotenuse of a Pythagorean triplet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM