For a positive integer $n$ both $5n+1$ and $7n+1$ are perfect squares. Show that $n$ is divisible by 24. My try:

$5n + 1 = k^2$
$7n +1 = \frac{7k^2-2}5$

Just don't know how to proceed after this. Please help.

If $x\equiv1(mod\ 3)$, we have $7n+1\equiv2(mod\ 3)$.
If $x\equiv2(mod\ 3)$, we have $5n+1\equiv2(mod\ 3)$.
But a perfect square cannot be congruent 2 mod 3, so x must be divisible by 3.
The remainders modulo 8 of the numbers are :
? for(n=0,7,print(n," ",Mod(7*n+1,8),"  ",Mod(5*n+1,8)))
0 Mod(1, 8)  Mod(1, 8)
1 Mod(0, 8)  Mod(6, 8)
2 Mod(7, 8)  Mod(3, 8)
3 Mod(6, 8)  Mod(0, 8)
4 Mod(5, 8)  Mod(5, 8)
5 Mod(4, 8)  Mod(2, 8)
6 Mod(3, 8)  Mod(7, 8)
7 Mod(2, 8)  Mod(4, 8)
?
Since the only quadratic residues modulo 8 are 0,1,4 , we must have $n\equiv0$ (mod 8)
Hence, 24 must divide n.
