# What is the sum of the prime numbers up to a prime number $n$? [duplicate]

How to find the sum of prime numbers up to a prime number $n$, that is for example: the sum of prime numbers up to 7 is: 2+3+5+7=17.

So what is the formula for finding: $$\sum_{k=0}^n p_k=????,$$ with $p_k$ being the $k$th prime.

Also if we have the sum of an even number of primes then would it be a new prime? Example: 2+3+5+7=17 and 17 is a prime. 2+3+5+7+11+13=41 and 41 is prime.

Thank you.

• For your second question: $2+3+5+7+11+13+17+19=77$ and $77$ is not a prime number. – user93957 Jan 1 '14 at 10:26
• OK thanks but what about the first question? – user118545 Jan 1 '14 at 10:28
• If you want an exact formula for the sum: No known formula. Asymptotic formulae can be obtained. – Daniel Fischer Jan 1 '14 at 11:37
• This question has previously been answered in each of these answers: Question 1, Question 2, Question 3. – Eric Naslund Jan 1 '14 at 21:17
• Do you mean from $k=1$? Isn't $p_0=1$? – Collag3n Mar 30 '19 at 19:34

In this answer, I use partial summation to show that

Asymptotic: For $k>-1$ we have $$\sum_{p\leq x}p^{k}=\text{li}\left(x^{k+1}\right)+O\left(x^{k+1}e^{-c\sqrt{\log x}}\right).$$

Where $\text{li}(x)=\int_2^x \frac{1}{\log t}dt$ is the logarithmic integral. Letting $k=1$, we see that $$\sum_{p\leq x } \text{li}\left(x^{2}\right)+O\left(x^{2}e^{-c\sqrt{\log x}}\right),$$ which implies that $$\sum_{p\leq x} p \sim \frac{x^2}{2\log x}.$$ The sum of the first $n$ primes is not as natural to work with. By using the fact that $p_n\sim n\log n$, along with the above asymptotic, it follows that $$\sum_{k=1}^n p_k \sim \frac{1}{2}n^2 \log n.$$ However the next few terms in the asymptotic expansion are not particularly pretty.

• Upto what limit can I use this to a good level of approximation? – tatan Dec 7 '17 at 4:52

$$\sum_{p\le x}p = \frac{x^2}{2\log x} + \frac{x^2}{2\log^2x} + \frac{x^2}{4\log^3x} + \frac{3x^2}{8\log^4x} + O\left(\frac{x}{\log^5x}\right).$$

I don't know such formula, but I can say your conjecture is not true. $$2+3+5+7+11+13+17+19=77=7\times 11.$$

• OK thanks but I'm interested in that first question. – user118545 Jan 1 '14 at 10:27
• No problem. Me too! – mathlove Jan 1 '14 at 10:28

There are formulas for computing prime numbers, the problem lies in the costs and time needed for that and there is often (or we don't know) no closed formula for that, like these ones:

1. $$p_n= 2+ \sum_{j=2}^{2^n} \left(\Bigg[\frac{n-1}{ \sum_{m=2}^{j} \left[\frac{1} { \sum_{k=2}^{m} [1-\frac{m}{k}+[\frac{m}{k}]] } \right]}\Bigg]-\left| \frac{n-1}{ \sum_{m=2}^{j} [\frac{1} { \sum_{k=2}^{m} [1-\frac{m}{k}+[\frac{m}{k}]] } ]}-1\right|\,\right)$$

2.

$$p_n=\left[ 1- \frac{1}{\log(2)} \log\left(-\frac{1}{2} + \sum_{d | P_{n-1}} \frac{\mu(d)}{2^d -1}\right)\right]$$ Where $$[x ] = floor(x)$$ is the largest integer not greater than x and $$\begin{cases} \mu(1)=1 ,& \\ \mu(n)=(-1)^r, & \text{if n is product of r distinct prime numbers} \\ \mu(n)=0, & \text{if n has one or more repeated prime factors} \\ \end{cases}$$

The second one is from "My Numbers, My Friends - Popular Lectures on Number Theory - Paulo Ribenboim", don't know from where is the first one.

I am sure there are more of formulas like that, even for exact n-th prime number, but why we don't use them?

Because we don't know any "effective" ones. Even if we compute some prime numbers with that, it would just take too long to find the big ones. So we use special algorithms for finding prime numbers, which are much faster, for example Sieve of Eratosthenes, and still seek for better and better ones :)

You can also find something here:

http://mathworld.wolfram.com/PrimeFormulas.html

https://oeis.org/A000040(look at formulas at the bottom of page)