A question about modulus for polynomials The other day my friend was asked to find $A$ and $B$ in the equation
$$(x^3+2x+1)^{17} \equiv Ax+B \pmod {x^2+1}$$
A method was proposed by our teacher to use complex numbers and especially to let $x=i$ where $i$ is the imaginary unit. We obtain from that substitution
$$(i+1)^{17} \equiv Ai+B \pmod {0}$$
which if we have understood it correctly is valid if we define  $a \equiv b \pmod n$ to be $a=b+dn$. Running through with this definition we have 
$$\begin{align*}
(i+1)^{17} &=\left(\sqrt{2}\left(\cos\left(\frac{\pi}{4}\right)+\sin\left(\frac{\pi}{4}\right)\right)\right)^{17}\\
&=\sqrt{2}^{17}\left(\cos\left(\frac{17\pi}{4}\right)+\sin\left(\frac{17\pi}{4}\right)\right) \tag{De Moivre}\\
&=256\left(\sqrt{2}\left(\cos\left(\frac{\pi}{4}\right)+\sin\left(\frac{\pi}{4}\right)\right)\right)\\
&=256\left(1+i\right) \\
&=256+256i\end{align*}
$$
which gives the correct coefficient values for $A$ and $B$.
Our questions are


*

*Why is this substitution valid to begin with?

*It seems here that the special case ($x=i$) implies the general case ($x$), why is that valid?


*

*It comes from the exponential form of complex numbers: $1+i$ has modulus $\sqrt 2$ and argument $\frac\pi 4$, so it writes as 
$$1+i=\sqrt2\,\mathrm e^{\tfrac\pi 4},\quad\text{and similarly}\quad 1-+i=\sqrt2\,\mathrm e^{-\tfrac\pi 4} $$
The substitution is valid because of the meaning of the congruence:
\begin{align}&(x^3+2x+1)^{17} \equiv Ax+B\enspace (\!\bmod {x^2+1)}\\ 
&\qquad\qquad\iff \exists q(x):\;(x^3+2x+1)^{17} =(x^2+1)q(x)+Ax+B  ,
\end{align}
so when you set $x=\pm i$, the first  term in the r.h.s. cancels.

*Setting $x=i$ yields an equation for $A$ and $B$, that's all. 

