Factoring $3^6-3^3 +1$ $3^6-3^3 +1$ factors?, 37 and 19, but how to do it using factoring, $3^3(3^3-1)+1$, can't somehow put the 1 inside  
 A: Viewing this as a quadratic in $3^3$ leads you to try to factorise $x^2-x+1$ or $x^6-x^3+1$, neither of which splits into anything useful. However, you can pull out a factor of $9$ from $3^6$ and a factor of $3$ from $3^2$ to obtain
$$3^6-3^3+1 = 9 \cdot 3^4 - 3 \cdot 3^2 + 1$$
And the quartic $9x^4-3x^2+1$ does factorise into two quadratic factors:
$$9x^4-3x^2+1 = (3x^2+3x+1)(3x^2-3x+1)$$
Now set $x=3$ and voilà!
A: It's a special case of:  completing the square leads to a difference of squares, i.e.
$$\begin{eqnarray}\overbrace{3^{\large 6}+1}^{\rm incomplete}-\,3^{\large 3}&=\ &\!\!\!\! \overbrace{(3^{\large 3}+1)^{\large 2}}^{\rm\!\!\! complete\ the\ square\!\!\!}\!\!\!\!-\color{#c00}{3\,3^{\large 3}}\ \ \text{so, factoring this} \it\text{ difference of squares}\\[.3em]
 &\!\!\!=&\! (\underbrace{3^{\large 3}+1\,\ -\, \color{#c00}{3^{\large 2}}}_{\Large 19})\ (\underbrace{3^{\large 3}+1\ +\,\color{#c00}{3^2}}_{\Large 37})\\
\end{eqnarray}$$
Generally $\ a^{\large 6} + b\, a^{\large 3} + c^{\large 2}\,$ factors if $\ \color{#c00}{ b= 2c\!-\!ad^{\large 2}}$ for some $d\,$ (above is $\,a,b,c,d = 3,-1,1,1)$
$$\qquad\ \begin{eqnarray}\overbrace{a^{\large 6}+c^{\large 2}}^{\rm incomplete}\!+b\,a^{\large 3}&=\ &\!\!\!\! \overbrace{(a^{\large 3}+c)^{\large 2}}^{\rm\!\!\! complete\ the\ square\!\!\!}\!\!\!\!+\color{#c00}{\overbrace{(b-2c)}^{\!\!\large -d^{\Large 2}a}\,a^{\large 3}}\ \ \text{so, factoring this} \it\text{ difference of squares}\\[.3em]
 &\!\!\!=&\! ({a^{\large 3}+c\,\ -\, \color{#c00}{da^{\large 2}}})\ ({a^{\large 3}+c\ +\,\color{#c00}{da^{\large 2}}})\\
\end{eqnarray}$$

Remark $ $ Below is another well-known example
$$\begin{eqnarray} n^4+4k^4 &\,=\,& \overbrace{(n^2\!+2k^2)^2}^{\rm\!\!\! complete\ the\ square\!\!\!}\!\!\!-\!(\color{#c00}{2nk})^2\ \ \text{so, factoring this} \it\text{ difference of squares}\\
 &\,=\,& (n^2\!+2k^2\ -\,\ \color{#c00}{2nk})\,(n^2\!+2k^2+\,\color{#c00}{2nk})\\
&\,=\,&(\underbrace{(n-k)^2}_{\rm\!\!\!\!\!\!\!\!\!\!\! complete\ the\ square\!\!\!\!\!\!\!\!}\ +\ \,k^2)\ \ \underbrace{((n+k)^2}_{\rm\!\!\!\!\!\!\!\!\!\!\! complete\ the\ square\!\!\!\!\!\!\!\!\!\!\!\!\!\!} +\,k^2)\\ \end{eqnarray}$$
A: $x^2-x+1$ factorises as $(x-\omega)(x+\omega^2)$ where $\omega^3=-1$.
Here $x=27$ and working modulo $27$ the cubes are $1,8,0,10,17,0,19,26, 0, 1, 8 \dots$ so $8^3\equiv -1$, and we can take $\omega = 8, \omega^2=64\equiv 10$ and obtain the factorisation $$(27-8)(27+10)=19\times 37$$
Since we have a cube root involved and the modulus is a power of $3$ there are some curiosities about the factorisation, but it checks out all the same.
A: Numbers having the form $n^2-n+1$ can never have prime factors congruent to $2$ modulo $3$.  Since $3$ is obviously out and any factorization must include a prime factor less than or equal to the square root if the number is composite, only factors $7,13,19$ need further investigation.  The factorization $19×37$ is tgen fairly easy to find.
