Sum of squares of consecutive integers equals to a square

177 Views Asked by At

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.

3

There are 3 best solutions below

0
On

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

0
On

There are at least $3$ ways of generating these. Note that these are so rare that the $20^{th}$ triple exceeds $15$ digits.

We begin with Euclid's formula shown here as: $$ A=m^2-k^2\qquad B=2mk \qquad C=m^2+k^2$$

The $m,k$ values for $\space A^2+(A\pm1)^2=C^2\space$ are pell numbers

$$p\in\big\{0,1,2,5,12,29,70,169,\cdots\big\} \space e.g.$$

$$ F(1,0)=(1,0,1)\\ F(2,1)=(3,4,5)\\ F(5,2)=(21,20,29)\\ F(12,5)=(119,120,169)\\ F(29,12)=(697,696,985)\\ F(70,29)=(4059,4060,5741)\\ F(169,70)=(23661,23660,33461)\\ \vdots$$

  1. The $n^{th}\space$ $(m,k)\space$ pair may be generated directly by the following formula.

\begin{equation} m_n= \frac{(1 + \sqrt{2})^{n+1} - (1 - \sqrt{2})^{n+1}}{2\sqrt{2}}\\ k_n= \frac{(1 + \sqrt{2})^n - (1 - \sqrt{2})^n}{2\sqrt{2}} \end{equation}

  1. These pairs may also be generated sequentially by \begin{equation} \quad m=k+\sqrt{2k^2+(-1)^k} \end{equation}

  2. The $A,B,C$ values may be generated without Euclid's formula by using the following formula with a seed [invalid] triple $T_0=(0,0,1)$. \begin{equation} A_{n+1}=3A_n+2C_n+1\\ B_{n+1}=3A_n+2C_n+2 \\ C_{n+1}=4A_n+3C_n+2 \end{equation}

0
On

Let $X=2x+1$ and let $Y=y$, then we get $$X^2-2Y^2=-1\tag{1}$$

The equation $X^2-2Y^2=-1$ is called as Pell's equation.

For details, see Pell equation.

All solutions are given as follows.
Let $(X_{0},Y_{0})$ is a fundamental solution of $X^{2}-2Y^{2}=-1.$

Thus, all of the solutions are derived from $(X_{0}+Y_{0}\sqrt{2})^n$ where $n$ is an odd integer.

Clearly, we know $(X_{0},Y_{0})=(1,1)$.

We take the integer part as $X$ and the coefficient of $\sqrt{2}$ as $Y$ as follows.

$(1+1\sqrt{2})^{3} = 7+5\sqrt{2} \implies (X,Y)=(7,5) \implies (x,y)=(3,5).$
$(1+1\sqrt{2})^{5} = 41+29\sqrt{2} \implies (X,Y)=(41,29) \implies (x,y)=(20,29).$
$(1+1\sqrt{2})^{7} = 239+169\sqrt{2} \implies (X,Y)=(239,169) \implies (x,y)=(119, 169).$

Thus, we can get the infinitely many integer solutions of equation $(1).$

                          [x,y]
                          [3, 5], 
                          [20, 29], 
                          [119, 169], 
                          [696, 985], 
                          [4059, 5741], 
                          [23660, 33461], 
                          [137903, 195025], 
                          [803760, 1136689], 
                          [4684659, 6625109], 
                          [27304196, 38613965],