Let $\omega=\exp(2\pi i/3)$. We have $$(a-b)(a-\omega b)(a - \omega^2 b) = a^3-b^3 = (a-b)(a^2 +ab + b^2),$$ so in particular, $(a-\omega b)(a - \omega^2 b) = a^2 + ab + b^2 $.
Let $n>1$ be indivisible by $3$, and $a>b\geq 1$. Then, $$\frac{a^{2n}+a^nb^n+b^{2n}}{a^2+ab+b^2}=\frac{(a^n-\omega b^n)(a^n-\omega^2 b ^n)}{(a-\omega b)(a -\omega^2 b)}=\frac{(a^n-(\omega b)^n)(a^n-(\omega^2 b )^n)}{(a-\omega b)(a -\omega^2 b)} $$ where in the last step we use the fact that $\omega^n,\omega^{2n}$ equals $\omega,\omega^2$ in some order (this would not be the case if $n$ were divisible by $3$). If $m\mid n$, then in the ring
$\mathbb{Z}[\omega]$ of Eisenstein integers, we have $(a^m-(\omega b)^m)\mid (a^n-(\omega b)^n)$, and similarly with $\omega^2$ instead of $\omega$. Thus, $$\frac{(a^m-(\omega b)^m)(a^m-(\omega^2 b )^m)}{(a-\omega b)(a -\omega^2 b)} \ \left\vert\ \frac{(a^n-(\omega b)^n)(a^n-(\omega^2 b )^n)}{(a-\omega b)(a -\omega^2 b)}\right . \tag{*}$$ Initially, we only know $(*)$ to be true in $\mathbb{Z}[\omega]$. However, both the LHS and RHS are real, so their ratio is a real element of $\mathbb{Z}[\omega]$. Since the real elements of $\mathbb{Z}[\omega]$ are precisely the integers, $(*)$ is also true in $\mathbb{Z}$. Now if $m$ is a non-trivial divisor (i.e. $1<m<n$), then $$a^2+ab+b^2<a^{2m}+a^mb^m+b^{2m}<a^{2n}+a^nb^n+b^{2n},$$ so the LHS of $(*)$ is a non-trivial divisor as well. It follows that $\frac{a^{2n}+a^nb^n+b^{2n}}{a^2+ab+b^2}$ can only be prime if $n$ is prime.
EDIT: An outline of a generalization. The key points of the proof above are
- We have a bivariate polynomial $P\in\mathbb{Z}[x,y]$ given by the homogenization of a univariate polynomial $p\in\mathbb{Z}[x]$ (that is, $P(x,y)=y^{\deg p}p(x/y)$)
- The roots of $p$ are distinct and given by a set $S$ of $k$th roots of unity
- We consider the primality of $P(a^n,b^n)/P(a,b)$ for $a>b\geq 1$ and $n$ such that $x\mapsto x^n$ permutes $S$
- We find that $P(a^m,b^m)/P(a,b)\mid P(a^k,b^k)/P(a,b)$ in the cyclotomic integers $\mathbb{Z}[\zeta]$ for $m\mid k$, where $\zeta=\exp(2\pi i /k)$
- We translate this to a factorization in $\mathbb{Z}$, using the fact that $\mathbb{Q}\cap\mathbb{Z}[\zeta]=\mathbb{Z}$
- We use the fact that $p(x)$ is increasing for $x>1$ to show that $1<m<k$ implies $P(a,b)<P(a^m,b^m)<P(a^n,b^n)$
- Hence $P(a^n,b^n)/P(a,b)$ is prime only if $n$ is prime
To generalize, we need the following
- $p(x)$ is increasing for $x>1$
- This is given by the Gauss-Lucas theorem, which guarantees that the zeroes of $p'$ lie in the unit disk.
- $\mathbb{Q}\cap\mathbb{Z}[\zeta]=\mathbb{Z}$
- The minimal polynomial of $\zeta$ is the cyclotomic polynomial $\Phi_k(x)\in\mathbb{Z}[x]$. By Euclidean division by $\Phi_k$, each element of $\mathbb{Z}[\zeta]$ is uniquely given as $r(\zeta)$ for an $r$ with $\deg(r)<\deg(\Phi_k)=\phi(k)$, and vice versa. Thus, $1,\ldots,\zeta^{\phi(k)-1}$ forms a basis of $\mathbb{Z}[\zeta]$ as a $\mathbb{Z}$-module. If the quotient module $\mathbb{Z}[\zeta]/\mathbb{Z}$ contains a nontrivial element $q\in \mathbb{Q}/\mathbb{Z}$ with denominator $m$, then $mq\in\mathbb{Z}$ is a $\mathbb{Z}$-linear combination of $\zeta,\ldots,\zeta^{\phi(k)-1}$, which contradicts the fact that $1,\ldots,\zeta^{\phi(k)-1}$ forms a basis of $\mathbb{Z}[\zeta]$. Hence $\mathbb{Q}\cap\mathbb{Z}[\zeta]=\mathbb{Z}$.
The question is then, for which $p$ do the first two points hold ($p$ has integer coefficients, zeroes are roots of unity)? Well, if $s$ lies in $S$, then so must all of its Galois conjugates. It follows that $S$ can be partitioned into Galois conjugacy classes, so $p$ factors as a product of cyclotomic polynomials $\Phi_d$ with $d\mid k$. If this factorization yields two or more factors, then $P(a^n,b^n)/P(a,b)$ is clearly composite. Thus, the only interesting case is when $p(x)=\Phi_k(x)$. Then, the $n$ of interest are precisely those coprime to $k$ ($n$ is a representative of $\text{Gal}(\mathbb{Q}(\zeta)/\mathbb{Q})\cong (\mathbb{Z}/k\mathbb{Z})^\times$). Thus, we get the following generalization:
Generalization:
If $n,k>1$ are coprime, $a>b\geq 1$ are coprime, and $P(x,y)=y^{\phi(k)}\Phi_k(x/y)$, then $P(a^n,b^n)/P(a,b)$ is prime only if $n$ is prime.
EDIT 2: There is a much simpler argument for why $\mathbb{Q}\cap\mathbb{Z}[\zeta]=\mathbb{Z}$. Since $\zeta$ is an algebraic integer, so are all the elements of $\mathbb{Z}[\zeta]$. On the other hand, the only algebraic integers in $\mathbb{Q}$ are those in $\mathbb{Z}$.
for(n=2,31, for(m=1,n-1, for(p=1, 1000, if(gcd(n,m)==1&&p%3!=0&&ispseudoprime(((n^2)^p+(mn)^p+(m^2)^p)/(n^2+nm+m^2)), print(n,",",m,",",p,",",isprime(p)))))) – Aurel-BG Sep 16 '24 at 16:32