Primes $p=x^2+27y^2$ and Ramanujan's $x_1^{1/3} + x_2^{1/3} + x_3^{1/3}$ I was trying to generalize,
$$\sqrt[3]{\sum_{k=1}^5\cos\big(\tfrac{2^k\cdot\,2\pi}{31}\big)}+\sqrt[3]{\sum_{k=1}^5\cos\big(\tfrac{2^k\cdot\,6\pi}{31}\big)}+\sqrt[3]{\sum_{k=1}^5\cos\big(\tfrac{2^k\cdot\,10\pi}{31}\big)} = -\sqrt[3]{\tfrac{-11+3\,\sqrt[3]{62}}{2}} \tag1$$
which is a special case of an identity of Ramanujan's. It led me to a family of primes $p=x^2+27y^2$ (A014752). Let $\beta=2\pi/p$ and define,
$$p=x^2+27y^2=6m+1$$
$$x_1=2\sum_{k=1}^{m}\cos\big(2^k\times\beta\big)$$
$$x_2=2\sum_{k=1}^{m}\cos\big(2^k\times3\beta\big)$$
$$x_3=2\sum_{k=1}^{m}\cos\big(2^k\times m\beta\big)$$
and,
$$a = -(x_1+x_2+x_3),\quad b=x_1x_2+x_1x_3+x_2x_3,\quad c=-x_1x_2x_3$$
I noticed some $a,b,c$ were just plain integers. In general, they were algebraic integers at most of a degree $n \leq 9$. The complete list for $p<1000$,
$$\begin{array}{|l|l|}
\hline
n&\quad\quad\quad p\\
\hline
1& 31, 43, 109, 157, 223, 229, 277, 283, 691, 733, 739, 811\\
2& 433, 457\\
3& 307, 439, 499, 643, 727, 919, 997\\
4& 601\\
6& (\text{for}\; p>1000?)\\
9& 127, 397\\
\hline
\end{array}$$
Questions:


*

*All these primes are also $4^m \equiv 1\pmod p$ (A016108). However, what distinguishes the primes $p$ in the first row from the others such that their $a,b,c$ are just plain integers? (It seems $p\equiv 1\pmod{24}$ have $n=2,4$.)

*Is there a $p$ with $n=6$? (I'm having trouble with $p=1297$.)


P.S. This is related to a MSE post of mine.
 A: Let $\zeta = e^{2\pi i/p}$ be a primitive $p$th root of unity. Then
$2 \cos (2\pi k/p) = \zeta^k + \zeta^{-k}$. The Galois group of $\mathbb Q(\zeta)$
is isomorphic to $(\mathbb Z/p \mathbb Z)^\times$ and acts transitively on
the powers $\zeta^k$ with $1 \le k \le p-1$. What you want is that the Galois
action fixes the set $\{x_1, x_2, x_3\}$. Now $x_j = \sum_{k \in A_j} \zeta^k$
where $A_1 = \{\pm 2^j : 0 \le k < m\} \subset \mathbb Z/p \mathbb Z$ (as a
multiset) and similarly for $A_2$ and $A_3$. So you want the natural action
of $(\mathbb Z/p \mathbb Z)^\times$ on $\mathbb Z/p \mathbb Z$ by multiplication
to just permute these three sets. This is only possible when $A_1$ consists of
all cubes in $(\mathbb Z/p \mathbb Z)^\times$.
In any case, 2 is a cube (since $p = x^2 + 27 y^2$; this is a famous result
due to Gauss). However, not every cube is necessarily $\pm$ a power of 2.
For example, for $p = 127$, the powers of 2 give you only 7 residue classes,
so $A_1$ has 14 distinct elements, but $(p-1)/3 = 42$ is larger.
The precise condition should be that 


*

*the order of 2 in the group
$(\mathbb Z/p \mathbb Z)^\times$ must be either $2m$ or else $m$
and $m$ must be odd (otherwise $2^{m/2} = -1$ and the positive
and negative powers of 2 in $A_1$ coincide), and

*$3$ is not a cubic residue mod $p$ (this is the condition for
$A_1$, $A_2$ and $A_3$ to be pairwise disjoint).


Note that this is consistent with your table. This answers Question 1.
To give an answer to Question 2, here is how you can determine the
degree $n$ of your algebraic integers $a$, $b$, $c$.
You consider the set $\{A_1, A_2, A_3\}$ and count how many images it has
under the natural action of $(\mathbb Z/p \mathbb Z)^\times$. This is $n$.
For $p = 1297$, I get $n = 648$, so it is not surprising that you had trouble.
(But then, 1297 is not of the form $x^2 + 27y^2$!) And $p = 3889$ has $n = 6$.
