Let $f(x) = x^2 - ax + b$ , where $a$ and $b$ are positive integers.

How many pairs of positive integers $(a, b)$ with $1\le a, b\le 2016$ for which every root of $f(f(x)) - x$ is an integer?

The answer is 43.

**
This section requires Javascript.
**

You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.

In terms of $a$ and $b$ , $f(f(x)) - x = x^4 - 2ax^3 + (a^2 - a + 2b)x^2 + (2a^2 - 2ab - 1)x + (b^2 - ab + b).$ At first, this seems like a mess to factor, but suppose we had a root $r$ of $f(x) - x = 0$ . Then we would also have a root of $f(f(x)) - x = 0$ since $f(r) = r \implies f(f(r)) - r = f(r) - r = 0.$ In other words, $f(x) - x$ is a factor of $f(f(x)) - x$ , so for some $u$ and $v$ , $f(f(x)) - x = \big( f(x) - x \big) \big(x^2 + ux + v \big) = \big( x^2 - (a + 1)x + b \big) \big( x^2 + ux + v \big).$ Consider the constant term and the quadratic coefficient in the expansion of $f(f(x)) - x$ above. Comparing those values to the factored form of $f(f(x)) - x$ , we see that we must have $bv = b^2 - ab + b, \quad b + v - (a + 1)u = a^2 - a + 2b,$ which we can solve to find $v = b - a + 1, \quad u = 1 - a.$ Now we are halfway to factoring $f(f(x)) - x$ : $f(f(x)) = \big( x^2 - (a + 1)x + b \big) \big( x^2 + (1 - a)x + (b - a + 1) \big).$ The roots of the two quadratic factors are $a + 1 \pm \sqrt{a^2 + 2a - 4b + 1}, \quad a - 1 \pm \sqrt{a^2 + 2a - 4b - 3}.$ The roots of $f(f(x)) - x = 0$ are integers if and only if the radicands are perfect squares. But the radicands differ by exactly 4, so this is only possible if $a^2 + 2a - 4b + 1 = 4, \quad a^2 + 2a - 4b - 3 = 0.$ Solving either equation for positive $a$ gives the relation we want. The roots of $f(f(x)) - x$ are integers exactly when $a = -1 + 2\sqrt{b + 1}, \qquad b = n^2 - 1 \geq 3,$ where $n$ is an integer. Based on this relation, there are $\boxed{43}$ pairs $(a,b)$ in the desired range.