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.

Just it's better to see that any polynomial $x^{3k-1}+x^{3n-2}+1$ has a factor $x^2+x+1$ for any naturals $k$ and $n$.
For example, your reasoning with $\omega\neq1$ and $\omega^3=1$ helps to understand it.
In our case we can get this factoring so:
$$x^5+x+1=x^5-x^2+x^2+x+1=(x^2+x+1)(x^3-x^2+1).$$
