# Positive integer $n$ such that $2n+1$ , $3n+1$ are both perfect squares

How many positive integer $n$ are there such that $2n+1$ , $3n+1$ are both perfect squares ?

$n=40$ is a solution . Is this the only solution ? Is it possible to tell whether finitely many or infinitely many solutions exist ?

The quick version is $n_0 = 0, \; \; n_1 = 40,$ then $$\color{magenta}{ n_{k+2} = 98 n_{k+1} - n_k + 40}.$$

Given an $(x,y)$ pair with $3x^2 - 2 y^2 = 1$ we then take $n = (x^2-1)/ 2 = (y^2 - 1)/ 3.$

The first few $x,y$ pairs are $$x=1, \; y= 1 , \; n=0$$ $$x=9, \; y=11, \; n=40$$ $$x= 89, \; y=109, \; n=3960$$ $$x=881, \; y=1079, \; n= 388080$$ $$x=8721, \; y=10681, \; n= 38027920$$ $$x=86329, \; y=105731, \; n= 3726348120$$ and these continue forever with $$x_{k+2} = 10 x_{k+1} - x_k,$$ $$y_{k+2} = 10 y_{k+1} - y_k.$$ $$n_{k+2} = 98 n_{k+1} - n_k + 40.$$

People seem to like these recurrences in one variable. The underlying two-variable recurrence in the pair $(x,y)$ can be abbreviated as $$(x,y) \; \; \rightarrow \; \; (5x+4y,6x+5y)$$ beginning with $$(x,y) = (1,1)$$ The two-term recurrences for $x$ and $y$ are just Cayley-Hamilton applied to the matrix $$A \; = \; \left( \begin{array}{rr} 5 & 4 \\ 6 & 5 \end{array} \right) ,$$ that being $$A^2 - 10 A + I = 0.$$

If $2n+1=x^2$ and $3n+1=y^2$ then $$3x^2-2y^2=1\ .$$ Multiplying by $-2$ and substituting $X=2y$, $Y=x$, this can be written as a Pell-type equation $$X^2-6Y^2=-2\ .$$ This has infinitely many solutions, some of which are given by $X=X_n$, $Y=Y_n$ where $$X_n+Y_n\sqrt6=(2+\sqrt6)(5+2\sqrt6)^n\ .\tag{*}$$ For example, taking $n=1$ gives $$X=22,\ Y=9,\ x=9,\ y=11$$ and hence $n=40$, the solution you have already. Equation $(*)$ gives the recurrences $$X_{n+1}=5X_n+12Y_n\ ,\quad Y_{n+1}=2x_n+5y_n\ ,$$ and it is then possible to eliminate the $Y$ terms to get $$X_{n+2}=10X_{n+1}-X_n$$ and similar relations for $x_n$ and $y_n$.

For a more detailed explanation of the method (applied to a slightly different equation), see my answer to this question.

If $2n+1$ is a square then it is (obviously?) of the form $4m^2+4m+1$ and thus $3n+1=6m^2+6m+1$ and so the question can be rephrased:

When is $6m^2+6m+1$ a square for integer $m$?

Which is trivially rephrased:

What are the integer solutions of $6x^2-y^2+6x+1=0$?

• @JohnFernley: $2n+1$ is odd, so if it's a square there is some odd number, say $2m+1$, which can be multiplied by itself to give $2n+1$, hence $2n+1=(2m+1)^2=4m^2+4m+1$. – Charles Jun 6 '14 at 5:08
I don't think it is possible to explicitly find all such $n's$. This condition of both $2n+1, 3n+1$ being squares has appeared in a lot of contests such as the Putnam but the question asked is always to prove some implication from this condition. For example, one can prove that if $2n+1, 3n+1$ are squares, $5n+3$ cannot be a prime and $40|n$.
We can do this modulo $4$. Since $n \equiv 0,1,2,3 \pmod{4}$, therefore $$2n+1 \equiv 1,3,1,3 \pmod{4}$$ and $$3n+1 \equiv 1,0,3,2 \pmod{4}.$$ However a square of an integer is only $0,1 \pmod{4}$. This means for both $2n+1$ and $3n+1$ to be squares $n \equiv 0 \pmod{4}$.
So let $n=4k$. Then we want $2n+1=8k+1$ and $3n+1=12k+1$ to be perfect squares. Let $8k+1=a^2$ and $12k+1=b^2$. Then $$4k=b^2-a^2=(b-a)(b+a).$$ Can you proceed from here?
$2n+1=x^2$ and $3n+1=y^2$ since , $x$ is odd let $x=2m+1$ $2n+1=4m^2+4m+1$ $n=2 (m)(m+1)$...... (eqn1) This means $4|n$; $y^2= 6m (m+1)$ $let y=2t+1$ From last two, $3 (m)(m+1)=2t (t+1)$ Since , $2|t (t+1)$; this implies $4|m (m+1)$ and this implies $8|n$ ... (from eqn 1). Now it remains to prove that $5|n$ Qudratic residue for $mod5$ are {0,1,4} So, $x^2= {0 or 1 or 4}$ $mod5$ Also $y^2= {0 or 1 or 4}$ $mod 5$ The only possible is $n= 0 mod 5$. (According to first two equations)