TITLE: A divisibility question concerning positive integers
QUESTION [7 upvotes]: Suppose $n$ is a positive integer such  that $3n+1$ and $4n+1$ are both perfect squares , then how do we prove that  $7|n$ ?

REPLY [5 votes]: Suppose $x^2=3n+1$ and $y^2=4n+1$. Then,
$$
4x^2-3y^2=1
$$
Using continued fractions, we find the solutions to this equation are $(x_k,y_k)$ where
$$
\begin{align}
(x_0,y_0)&=(1,1)\\
(x_1,y_1)&=(13,15)\\
(x_k,y_k)&=14(x_{k-1},y_{k-1})-(x_{k-2},y_{k-2})
\end{align}
$$
Looking at $(x_k,y_k)\text{ mod }7$, we see
$$
\begin{align}
(x_0,y_0)&=(1,1)\\
(x_1,y_1)&=(-1,1)\\
(x_k,y_k)&=-(x_{k-2},y_{k-2})
\end{align}
$$
Thus, $x_k^2\equiv y_k^2\equiv1\pmod{7}$ and therefore, $n\equiv0\pmod{7}$.

Solving Pell's equation with Continued Fractions
When solving $4x^2-3y^2=1$, we want $\frac yx$ to underestimate $\frac2{\sqrt3}$.
The continued fraction for $\frac2{\sqrt3}$ is $(1;\overline{6,2})$:
$$
\begin{array}{c|c}
\frac{2\sqrt3}{3}&2\sqrt3+3&\frac{2\sqrt3+3}{3}&2\sqrt3+3\\
\hline\\
1&6&2&\dots\\
\end{array}
$$
Thus, the convergents are
$$
\begin{array}{c|c}
&&&1&6&2&6&2\\
\hline y_k&0&1&\color{#C00000}{1}&7&\color{#C00000}{15}&97&\color{#C00000}{209}\\
\hline x_k&1&0&\color{#C00000}{1}&6&\color{#C00000}{13}&84&\color{#C00000}{181}\\
\hline k&&&0&1&2&3&4
\end{array}
$$
The underestimates are in red (even $k$).
Due to the alternating continuants, for $k\gt0$, we have
$$
a_{2k}=2a_{2k-1}+a_{2k-2}\quad\text{ and }\quad a_{2k-1}=6a_{2k-2}+a_{2k-3}
$$
which leads to a recursion for the underestimates:
$$
a_{2k}=14a_{2k-2}-a_{2k-4}
$$
where $a_k=(x_k,y_k)$.