When is the fraction $\frac{n+7}{2n+7}$ the square of a rational number? 
Find all positive integers $n$ such that the fraction $\dfrac{n+7}{2n+7}$ is the square of a rational number.

The answer says $n = 9,57,477$, but how do we prove this? I wrote $\dfrac{n+7}{2n+7} = \dfrac{a^2}{b^2}$ for some $a,b \in \mathbb{Z^+}$ and $\gcd(a,b) = 1$. We know that $\gcd(n+7,2n+7) = \gcd(n+7,7) = 1,7$ and so $n+7$ and $2n+7$ must both be perfect squares or their greatest common divisor is $7$. How do we find all values for which this is the case?
 A: $$\gcd(n+7,2n+7)=\gcd(n+7,n)=\gcd(7,n)\in\{1,7\}$$
If the $\gcd=1$, then $n+7,2n+7$ are both squares:
$$n+7=a^2,2n+7=b^2\implies 2a^2-b^2=7$$
If the $\gcd=7$, then $\frac{n+7}{7},\frac{2n+7}{7}$ are both integer squares. Write $n=7m$:
$$m+1=a^2,2m+1=b^2\implies2a^2-b^2=1$$
Finding exact solutions from here requires study of Pell's equation, as indicated in the comments.


*

*The first equation has solutions starting with
$\{(2,1),(8,11),\cdots\}$

*The second equation has solutions starting with
$\{(1,1),(5,7),(41,29),\cdots\}$.
These can be generated by looking at $(3+\sqrt2)(1+\sqrt2)^{2k},(1+\sqrt2)^{2k+1}$ respectively for integer $k$. Noting that $\frac{1}{1+\sqrt2}=-(1-\sqrt2)$ tells us that for the second of these sequences, we cann afford to simply look at $k\ge0$.
In the first case, given $2a^2-b^2=7$, note that taking $n=b^2-a^2$ gives $a^2=n+7,b^2=2n+7$ as desired, i.e. the fraction in question is a square. A slight adaptation of this resolves the second case.
Clarification: When I say "these can be generated by looking at $(a+b\sqrt2)^k$", I refer to the fact that by writing $(a+b\sqrt2)^k=A_k+B_k\sqrt2$ for integers $A_k,B_k$, we will have $2B_k^2-A_k^2=1$ or $7$, depending on this sequence. This method makes use of techniques from algebraic number theory, where we learn that the function $N:a+b\sqrt2\to a^2-2b^2$ is multiplicative.
A: There are more solutions (n<1000000):
$$
\begin{array}{c}
 9 \\
 57 \\
 168 \\
 477 \\
 2109 \\
 5880 \\
 16377 \\
 71817 \\
 199920 \\
 556509 \\
\end{array}
$$
so you just plug these values of $n$ and check otherwise the question does not make sense. Also One solution in your list is missing for n<500.
Added after observation of ross-millikan:
$n+7$ and $2n+7$ can have common multiplier, is so than $2*(n+7)-(2n+7)$ is also devisible by the same number which is clearly $7$, so the theorem is that if numerator and denominator have a common multiplier it can only be $7$. Thus we have two possibilities
a) $n+7=a^2$ and $2n+7=b^2$
b) $n+7=7 a^2$ and $2n+7=7 b^2$
for b) n should be divisible by $7$
