How would you find the trigonometric roots of a cubic?
Solution 1:
If you wish to express as roots of cubics the sums of trigonometric functions with arguments that use a prime of form $p=6\color{blue}n+1$, then the number of addends is $\color{blue}n$. Thus, the reason you couldn't find $p=31$ was that you should have used $\color{blue}5$ addends.
$p=31$
A root of $$x^3+x^2-(2\times\color{blue}5)x-8=0\tag1$$ (note the $5$) is given by $$x_1 = 2\left(\cos\tfrac {2\pi}{31}+\cos\tfrac {4\pi}{31}+\cos\tfrac {8\pi}{31}+\cos\tfrac {16\pi}{31}+\cos\tfrac {32\pi}{31}\right) =3.083872\dots$$ More succinctly, let $\displaystyle\beta=\frac{2\pi}{31}$, then, $$x_1=2\sum_{k=1}^5\cos\big(2^k\times\beta\big)=3.083872\dots\\x_2=2\sum_{k=1}^5\cos\big(2^k\times3\beta\big)=-0.786802\dots\\x_3=2\sum_{k=1}^5\cos\big(2^k\times5\beta\big)=-3.29707\dots$$
$p=43$
Similarly, given the cubic, $$x^3+x^2-(2\times\color{blue}7)x+8=0\tag2$$ Let $\displaystyle\gamma=\frac{2\pi}{43}$, then the roots are, $$x_1=2\sum_{k=1}^7\cos\big(2^k\times\gamma\big)=2.88824\dots\\x_2=2\sum_{k=1}^7\cos\big(2^k\times3\gamma\big)=0.615072\dots\\x_3=2\sum_{k=1}^7\cos\big(2^k\times7\gamma\big)=-4.50331\dots$$ though not all primes $p=6n+1$ will have such neat cubic roots. The family $p=31,43,109,\dots$ is discussed in this post.
P.S. See also mercio's general answer here which uses cosets.
Solution 2:
1) Reduce the standard way your equation $x^3+x^2-10x-8=0$ to the form $$x^3+ax+b=0\qquad(*)$$
2) Since you have the identity $$4\cos^3\theta-3\cos \theta-\cos 3\theta=0\qquad(**)$$ make $x=u\cos\theta$ in $(*)$ so you get $$u^3\cos^3\theta+au\cos\theta+b=0\iff4\cos^3\theta+\frac{4au}{u^3}\cos\theta+\frac{4b}{u^3}\qquad(***)$$
3) In order to refer $(***)$ to $(**)$ you need to take $$-3=\frac{4au}{u^3}\iff u=2\sqrt{\frac{-2a}{3}}$$ and $$\frac{4b}{u^3}=-\frac{3b}{2a}\sqrt{\frac{-3}{a}}$$ which gives $$\cos3\theta=\frac{3b}{2a}\sqrt{\frac{-3}{a}}$$
Hence your roots are given by $$x_k=2\sqrt{\frac{-a}{3}}\cos\frac{\theta_k}{3}$$ where $$\theta_k=\arccos\left(\frac{3b}{2a}\sqrt{\frac{-3}{a}}-\frac{2k\pi}{3}\right);\space k=0,1,2$$
Note.-You can use this method because the three roots of your equation are real.