I am not at all mathematics guy, just had a question. How can I find possible pairs of consecutive integers whose sum of squares equals to a square?
I understand equation will be something like:
x² + (x + 1)² = y²
x² + x² + 2x + 1 = y2
2x² + 2x + 1 = y²
where x, x+1 consecutive integers.
But, how can I mathematically find (x, x+1) pairs, example:
3² + 4² = 5²
20² + 21² = 29²
119² + 120² = 169²
from the equation? I am actually trying to write a program which will find these pairs without brute force. Please help me with the logic (maths).
Is there a possible way to find these pairs without "substituting x by every number from 1 to n and checking if y² is a perfect square"? I mean to avoid brute force or decrease brute force complexity, maybe like simplifying the equation 2x² + 2x + 1 = y² even more.
According to Euclid's formula, we have $$ a=m^2-n^2, b=2mn, c=m^2+n^2$$ You are asking for $$m^2-n^2=2mn\pm 1 $$ Upon adding $2n^2$ to both sides we get
$$(m-n)^2=2n^2\pm 1$$ Thus we choose positive integers $n$ such that one of $2n^2\pm 1 $ is a perfect square and solve $$ (m-n)^2=2n^2\pm 1$$ for $m$ For example:
$$n=1, 2n^2-1=1, (m-1)^2=1, m=2$$ which gives us $$(a,b,c)=(3,4,5)$$ $$ n=2, 2n^2+1=9, (m-2)^2=9, m=5$$ which gives us $$ (a,b,c)=(21,20,29)$$ With $n=5$ we get $$(a,b,c)= (119,120,169)$$ With $n=12$ we get $$(a,b,c)= (697,696,985)$$ And with $n=985$ we get $$(a,b,c)= (4684659,4684660,6625109)$$