$\newcommand{\kron}[2]{\left( \frac{#1}{#2} \right)}$
We are interested in the value of the Legendre symbol $\kron{40}{97} = \kron{8}{97} \kron{5}{97}$. In general, $2$ behaves differently from the rest of the primes.
By what is sometimes called the second supplemental law of quadratic reciprocity, we know that $\kron{2}{p} = (-1)^{(p^2-1)/8}$, or rather that $2$ is a square mod a prime iff that prime is congruent to $\pm 1 \pmod 8$. Since $97 \equiv 1 \pmod 8$, we see that $2$ is a square mod $97$. (Proofs of the second supplemental law can be found both here on MSE and on my site, and in most elementary number theory texts).
We must still consider $\kron{5}{97}$. By quadratic reciprocity, this is the same as $\kron{97}{5} = \kron{2}{5}$. The squares mod $5$ are $1$ and $4$ (or alternatively, $5$ is not congruent to $\pm 1 \pmod 8$), so $\kron{2}{5} = -1$.
In total, we have that $\kron{40}{97} = 1 \cdot -1 = -1$, which means that $40$ is not a square mod $97$. And so this quadratic Diophantine equation has no solution. $\diamondsuit$