<s>[INST] What is the best way to solve an equation of the form $(f(x))^2-a(f(x))+b=x$? On a math contest I was told to solve the equation $$(x^2-3x+1)^2-3(x^2-3x+1)+1=x$$
For this particular problem I simplified by letting     $$a\equiv x^2-3x+1$$
Then I continued with $$a^2-3a+1-x=0$$
$$a=\frac{3\pm\sqrt{9-4\left(1-x\right)}}{2}$$
$$3\pm\sqrt{5+4x}=2a=2x^2-6x+2$$
$$\pm\sqrt{5+4x}=2x^2-6x-1$$
 I am not sure how to finish off this problem. Also, I have seen a bunch of problems like this in the past. What is the best way to approach a problem like this and also how could I finish solving this problem? Could someone also explain why f(f(x))=x has the same solutions as f(x)=x.
 [/INST] Add $x^2-3x+1$ to both sides, giving
$$(x^2-3x+1)^2 - 2(x^2-3x+1) + 1 = x + x^2-3x+1 = x^2-2x+1,$$
or
$$((x^2-3x+1)-1)^2 = (x-1)^2.$$
Thus $(x^2-3x+1)-1 = \pm (x-1)$.  The plus sign gives
$$x^2-4x+1=0\quad\Rightarrow\quad x = 2\pm\sqrt{3}.$$
The minus sign gives
$$x^2-2x-1=0\quad\Rightarrow\quad x = 1\pm\sqrt{2}.$$
</s>