Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 546
user2156850 Avatar asked Oct 05 '22 18:10

user2156850


1 Answers

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).

like image 76
BeniBela Avatar answered Oct 13 '22 11:10

BeniBela