It is known that the period of continued fraction of a prime $\sqrt p$ is odd if and only if $p \equiv 1 \pmod 4$. So when $p \equiv 3 \pmod 4$, the period is even.
But how do I prove the period of continued fraction of $\sqrt p$ where $p$ $\equiv 3 \pmod 8$ is $2n$ ($n$ is odd) while the period of continued fraction of $\sqrt p$ where $p$ $\equiv 7 \pmod 8$ is $2n$ ($n$ is even)?
I tried some examples and find that $x^2-p\cdot y^2=2(-1)^n$ appears in the half of the period $- 1$ where $x$ and $y$ are its convergent, for instance continued fraction of $\sqrt p$ is $[a_0 ; a_1,a_2,\cdot\cdot\cdot,a_n]$, then $p_{\frac n 2 -1}$ and $q_{\frac n 2 -1}$ satisfies the equation $x^2-p\cdot y^2=2(-1)^n$ where $x=p_{\frac n 2 -1}$ and $y=q_{\frac n 2-1}$.
I recall that Legendre symbol $\left(\displaystyle \frac {~2~}{~p~}\right)$ is $1$ when $p \equiv 7 \pmod 8$ while $\left(\displaystyle \frac {~2~}{~p~}\right)$ is $-1$ when $p \equiv 3 \pmod 8$, but cannot figure it out how I can relate them.
Is this the right way to approach?