Sequence $ a_0=1,a_1=3$ and $a_{n+2}=4a_{n+1}-a_n $. Prove that $2017|a^2_{2017}-4a_{2017}+3$ I need a solution verification for next problem.

Let sequence $a_0,a_1,...$  be such that:
$ a_0=1,a_1=3$ and $a_{n+2}=4a_{n+1}-a_n $. Prove that $$2017\mid a^2_{2017}-4a_{2017}+3$$

By solving this recurrence we get $$a_n = {3+\sqrt{3}\over 6}(2+\sqrt{3})^n+{3-\sqrt{3}\over 6}(2-\sqrt{3})^n$$
Notice that $p:=2017$ is prime. By Gauss reciprocity law we have $\big({3\over p}\big) = 1$ so there exists $a\in \mathbb{Z}_p$ such that $a^2\equiv 3 \pmod p$. Consider now this sequence in the field $\mathbb{Z}_p$. So we have $$6a_n = (3+a)(2+a)^n+(3-a)(2-a)^n$$
By Fermat little theorem we have $$6a_p\equiv _p (3+a)(2+a)+(3-a)(2-a) \equiv_p 18$$
So, since $p\nmid 6$ we have $a_p \equiv_p 3$ and thus a conclusion.

Your proof works.
I wondered why they chose $$f(m)=m^2-4m+3=(m-1)(m-3),$$ I see when $p=5,7$ that $a_p\equiv 1\pmod p.$
I wonder if this is true for all primes. To prove that, you’d want to to show that if $\left(\frac 3p\right)=-1$ then $a_p\equiv 1\pmod p.$

Proof as outlined by commenter Derive Foiler.
If $\left(\frac 3p\right)=-1$ then we have $F_{p^2}=\mathbb F_{p}[\sqrt{3}].$ And the map $f:F_{p^2}\to F_{p^2}$ sending $u\to u^p$ is a non-trivial automorphism. So $f(a+b\sqrt{3})=a-b\sqrt 3.$
Then:
$$6a_n = (3+\sqrt{3})(2-\sqrt{3})+(3-\sqrt{3})(2+\sqrt 3)=6$$
So $a_n\equiv 1\pmod p.$

This shows more generally, if $T_{n+1}=bT_n+cT_{n-1}$ with $b,c$ integers and $T_0,T_1$ integers, and $b^2+4c$ is not a perfect square, then when $p\not\mid b^2+4c$ is an odd prime, then $T_p$ is congruent to one of two values, depending on the value of $\left(\frac{b^2+4c}{p}\right).$
When $\left(\frac{b^2+4c}p\right)=1,$ the specific values is $T_p\equiv T_1\pmod p.$
You also get when $\left(\frac{b^2+4c}{p}\right)=-1,$ that $T_p \equiv -cT_{-1}\pmod{p}$ where $T_1=bT_0+cT_{-1},$ or $-cT_{-1}=bT_0-T_1.$ For example, in our current question, $c=-1,b=4$ we get $-cT_{-1}=1.$
So you also get only one value if $bT_0-T_1=-cT_{-1}=T_0,$ or if $(b-1)T_0=T_1.$
A closed form when $T_0=0$:
$$T_p\equiv \left(\frac{b^2+4c}{p}\right)T_1$$
which becomes much easier if $T_0=0.$
For another example, for Fibonacci numbers, $b^2+4c=5,$ then if $p\equiv\pm 1\pmod{5}$ then $F_p\equiv F_1=1\pmod p$ and when $p\equiv \pm 2\pmod 5$ then $F_p\equiv F_0-F_1=-1\pmod{p}.$
(If $b^2+4c$ is a perfect square, including $0,$ then there is one value $d$ such that $T_p\equiv d\pmod p$ for all odd primes $p\not\mid b^2+4c.$ (For $b^2+4c=0,$ it is one value for any $p\not\mid b.$)
