Legendre symbol, second supplementary law $$\left(\frac{2}{p}\right) = (-1)^{(p^2-1)/8}$$
how did they get the exponent. May be from Gauss lemma, but how.
Suppose we have a = 2 and p = 11. Then n = 3 (6,8,10), but not 
$$15 = (11^2-1)/8$$
n is a way to compute Legendre symbols from Gauss lemma:
$$\left(\frac{a}{p}\right) = (-1)^n$$

Here is a proof from Ireland-Rosen Ch-6 (The key idea is to work in $ \overline{\mathbb{Z}} $, modulo $ p \overline{\mathbb{Z}} $) :
Let $ p $ be an odd prime. We have $ \left( \frac{2}{p} \right) \equiv 2^{\frac{p-1}{2}} (\text{mod } p\mathbb{Z} ) $. Notice we can write $ 2^{\frac{1}{2}} $ as $ 2^{\frac{1}{2}} = 2 \cos \left(\frac{2 \pi}{8} \right) = \zeta + \frac{1}{\zeta} $ (where $ \zeta := e^{\frac{i 2 \pi}{8}} $), and now both $ \zeta, \zeta + \frac{1}{\zeta} \in \overline{\mathbb{Z}} $ (because $\zeta$ satisfies $ X^4 + 1 = 0$, and $ \zeta + \frac{1}{\zeta} $ satisfies $ X^2 - 2 = 0 $).
So we have $ \left( \frac{2}{p} \right) \equiv \left( \zeta + \frac{1}{\zeta} \right)^{p-1} (\text{mod } p\overline{\mathbb{Z}}), $ in $ \overline{\mathbb{Z}} $. Now writing $ \eta := \zeta + \frac{1}{\zeta} ( = 2^{\frac{1}{2}} ) $, we get $ \left( \frac{2}{p} \right) \eta \equiv \eta^p \equiv \zeta^p + \zeta^{-p} \, ( \text{mod } p\overline{\mathbb{Z}})$.
But notice $ \zeta^p + \zeta^{-p} $ is determined by the value of ($ p $ mod $ 8 $), and it is in fact $ 2^{\frac{1}{2}} $ when $ p \equiv \pm 1 \, (\text{mod } 8) $ and $ -2^{\frac{1}{2}} $ when $ p \equiv \pm 3 \, ( \text{mod } 8 ) $. We can encapsulate this casework by writing $ \zeta^p + \zeta^{-p} = (-1)^{\frac{p^2-1}{8}} 2^{\frac{1}{2}} $ (because $ p $ can only be of the form $ 8k \pm 1 $ or $ 8k \pm 3 $, and $ (-1)^{\frac{p^2-1}{8}} $ is $ (-1) $ if former and $ 1 $ if latter).
So finally $ \left( \frac{2}{p} \right) \eta \equiv (-1)^{\frac{p^2-1}{8}} \eta \, (\text{mod }p\overline{\mathbb{Z}}) $. Notice multiplying by $ \eta $ makes both sides integers. Therefore $ \dfrac{\left( \frac{2}{p} \right) 2 - (-1)^{\frac{p^2 - 1}{8}} 2 }{p} \in \overline{\mathbb{Z}} \cap \mathbb{Q} = \mathbb{Z} $, giving us $ \left( \frac{2}{p} \right) = (-1)^{\frac{p^2 -1}{8}} $.
