An interesting observation on the roots of certain polynomials

Consider the following polynomial: $$\sum_{k=1}^{n}\text{prime}(k)x^{k-1}$$ where $n\in\mathbb{N}$ and $\text{prime}(n)$ is the $n$th prime. The first few polynomials are:
\begin{align} n=1&:\quad 2\\ n=2&:\quad 2+3x\\ n=3&:\quad 2+3x+5x^2\\ n=4&:\quad 2+3x+5x^2+7x^3 \end{align} Consider the number of real roots of these polynomials. The first few number of real roots of these polynomials form the sequence $0,1,0,1,0,1,0,1,0,1,0,1,0,1,...$. This alternating zeros and $1$'s pattern holds for all primes less than $1000$ (verified by @Quimey) I have two questions:

  • Does this pattern always hold? Said in another way, is the number of real roots of the polynomial $\sum_{k=1}^{n}\text{prime}(k)x^{k-1}$ always equal to $(1 + (-1)^{n})/2$?
  • Is yes, how can we prove it?

Note: Sorry if I missed something "trivial", I don't have much experience in mathematics.


The pattern breaks down at $n = 2437$, where the polynomial has two real roots according to the following code in SageMath (which outputs 2).

R.<x> = PolynomialRing(ZZ)
primes = primes_first_n(2437)
p = sum(np.array(primes)*np.array([x**i for i in range(len(primes))]))
print(pari(p).polsturm())

I think this is the smallest such $n$. I'm not sure why the sequence breaks there in particular; the prime gaps around $\text{prime}(2437)=21727$ don't look particularly special.

We can exclude an error in the software by checking the exact value of the polynomial at rational points near the two roots (thanks to Ivan Neretin for the suggestion). I used SymPy's Rational class, but this could also be done using Python's int type and multiplying by the largest denominator power in the polynomial to avoid fractions. The output of the code

import sympy
n = 2437
sympy.sieve.extend_to_no(n)
for numerator in [-9967, -9966, -9965]:
    x = sympy.Rational(numerator, 10000)
    print(sympy.functions.sign(sum([sympy.sieve[i+1]*x**i for i in range(n)])))

is 1, -1, 1, which proves that the polynomial has at least two real roots (by continuity).