As $\displaystyle2017\equiv17\pmod{1000},2017^m\equiv17^m$ for any integer $m$
Use Carmichael function, $\lambda(1000)=100$
$$\implies17^{(2016^{2015})}\equiv17^{(2016^{2015})\pmod{100}}\pmod{1000}$$
Now $2016\equiv16\implies2016^{2015}\equiv16^{2015}\pmod{100}$
As $(16,100)=4$ let use find $16^{2015-1}\pmod{100/4}$
$16^{2014}=(2^4)^{2014}=2^{8056}$
As $\displaystyle\lambda(25)=\phi(25)=20$ and $8056\equiv16\pmod{20},2^{8056}\equiv2^{16}\pmod{25}$
$2^8=256\equiv6\pmod{25}\implies2^{16}\equiv6^2\equiv11$
$\implies16^{2014}\equiv11\pmod{25}$
$\implies16^{2014+1}\equiv11\cdot16\pmod{25\cdot16}\equiv176\pmod{400}\equiv76\pmod{100}$
$$\implies17^{(2016^{2015})}\equiv17^{76}\pmod{1000}$$
Now $$17^{76}=(290-1)^{38}=(1-290)^{38}\equiv1-\binom{38}1290+\binom{38}2290^2\pmod{1000}$$
Now $\displaystyle38\cdot29=(40-2)(30-1)\equiv2\pmod{100}\implies\binom{38}1290\equiv20\pmod{1000}$
and $\displaystyle\binom{38}229^2=\dfrac{38\cdot37}2(30-1)^2\equiv3\pmod{10}$
$\displaystyle\implies\binom{38}2290^2\equiv3\cdot100\pmod{10\cdot100}$
We give a counting argument. Let $p$ be an odd prime, and suppose that $a$ is not divisible by $p$. Then the congruence $x^2\equiv a\pmod{p^k}$ has either no solution or two solutions.
To prove this, suppose $b^2\equiv a\pmod{p}$. Then from $x^2\equiv b^2\pmod{p^k}$ we conclude that $p^k$ divides $(x-b)(x+b)$. Since $p$ cannot divide both, we conclude that $p^k$ divides one of $x-b$ or $x+b$. So if the congruence has at least one solution $b$, it has exactly two, namely $b$ and $-b$.
The function $f(x)=x^2$ (modulo $p^k$) maps the set $H$ of numbers between $1$ and $p^k-1$ that are not divisible by $p$ to $H$. By the above, this function is two to one.
So half of the elements of $H$ are QR of $p^k$, and half are not. Which half? The ones congruent to a quadratic residue modulo $p$. For if $a$ is not a square modulo $p$, it cannot be a square modulo $p^k$.
The above argument proves that for odd primes $p$, every quadratic residue modulo $p$ is a quadratic residue modulo $p^k$. The result does not hold for $p=2$: Note that $3$ is a quadratic residue of $2$ but not of $4$.
Best Answer
Right so $40^{42} \equiv 1 \mod 49$ so $40^{128}\equiv 40^2 \equiv (-9)^2 \equiv 81 \equiv 32 \mod 49$