If $n$ is a positive integer greater than 1 such that $3n+1$ is perfect square, then show that $n+1$ is the sum of three perfect squares. If $n$ is a positive integer greater than 1 such that $3n+1$ is perfect square, then show that $n+1$ is the sum of three perfect squares.
My work:
$3n+1=x^2$
$3n+3=x^2+2$
$3(n+1)=x^2+2$
$(n+1)=\dfrac{x^2+2}{3}$
I have no clue what to do next. Please help!

If $\displaystyle 3n+1=a^2, (a,3)=1\implies a$ can be written as $\displaystyle3b\pm1$ where $b$ is an integer
So we have $\displaystyle 3n+1=(3b\pm1)^2\implies n=3b^2\pm2b$
$\displaystyle n+1=3b^2\pm2b+1=b^2+b^2+b^2\pm2b+1=b^2+b^2+(b\pm1)^2$
