How to deduce this factorization of $x^5+x+1$ by looking at $\int\frac{3x^4+2x^3-2x+1}{x^5+x+1}dx$? The question is:

$$\int\frac{3x^4+2x^3-2x+1}{x^5+x+1}dx$$

I tried a lot but couldn't solve it so I looked at the solution which is:
$$x^5+x+1=(x^2+x+1)(x^3-x^2+1)$$ and we can write $$3x^4+2x^3-2x+1=(x^3-x^2+1)+(3x^2-2x)(x^2+x+1)$$
which effectively reduces the integral to very simple ones.
My question is how they deduced the factorization of the denominator. After looking at the solution I think that if we put $x=1,x=\omega$ and $x=\omega^2$ we can deduce this but this was not immediately obvious to me. Is there some sort of hint you can get by looking at the integrand or is it simply a matter of less experience?
Any help would be appreciated.

Hmm. I'd look at it and say "There's no rational root" because $x = \pm 1$ doesn't work. So there's some irrational root, $\alpha$, and two complex-conjugate pairs.
So there's no nice obvious linear factor I can write down.
Then I'd say "Maybe there's a quadratic factor." I can assume it's monic, so I'm looking to write
$$
x^5 + x + 1  = (x^2 + ax + b) (x^3 + px^2 + qx + r).
$$
from which I can expand to get
$$
x^5 + x + 1  = x^5+(p + a)x^4 + (q + ap + b) x^3 + (ra + bq)x + br 
$$
if I've done the algebra right. Equating coefficients I see that
\begin{align}
0 &= a + p\\
0 &= q + ap + b\\
1 &= ra + bq\\
1 &= br
\end{align}
so $ p = -a$, and $r = \frac1b$,and these equations become
\begin{align}
0 &= a + -a\\
0 &= q - a^2 + b\\
1 &= \frac1b a + bq\\
1 &= b(1/b)
\end{align}
which simplify down to
\begin{align}
q &= a^2 - b\\
b &= a + b^2q\\
\end{align}
or
\begin{align}
q &= a^2 - b\\
0 &= b^2 q - b + a
\end{align}
That last equation is a quadratic in $b$ or $q = 0$. The first choice yields
$$
b = \frac{1 \pm \sqrt{1-4aq  }}{2q}
$$
The second choice yields $b = a, q = 0$, from which we find that $r = 1, p = -1$, which is a nice solution, so we can stop looking at the first case. (Yay!)
