Factoring $x^7+3x^6+9x^5+27x^4+81x^3+243x^2+729x+2187$
$$\frac{P(x)}{3^7}=\sum_{k=0}^7\left(\frac{x}{3}\right)^k=\frac{\left(\frac{x}{3}\right)^8-1}{\frac{x}{3}-1}$$
For the sake of an alternative, less clever approach: pretending to not notice the pattern of increasing powers of $3$, the root $x=-3$ can also be found by brute force using the rational root theorem. Quite obviously, the polynomial has no positive roots, so it's enough to try the negative divisors of $2187=3^7$, which finds $-3$ pretty quickly.
Then, dividing by the factor of $x+3$ using (for example) polynomial long division gives:
$$ P(x)=(x+3)(x^6 + 9 x^4 + 81 x^2 + 729) $$
The sextic that remains to be factored is a cubic in $y=x^2$:
$$ Q(y) = y^3+9y^2+81y+729 $$
Using the rational root theorem again, $y=-9$ is a root, then dividing by $y+9$ gives:
$$ Q(y) = (y+9)(y^2+81) $$
So in the end $P(x)=(x+3)Q(x^2)=(x+3)(x^2+9)(x^4+81)\,$.
$$P(X)=x^7+3x^6+3^2x^5+3^3x^4+3^4x^3+3^5x^2+3^6x+3^7=\frac{x^8-3^8}{x-3}\\=\frac{(x^4-3^4)(x^4+3^4)}{x-3}=\frac{(x^2-3^2)(x^2+3^2)(x^4+3^4)}{x-3}=\frac{(x-3)(x+3)(x^2+3^2)(x^4+3^4)}{x-3}$$