# sum of prime counting function values over a finite intrval

I am interested in finding an exact or close expression of $$\sum_{k=a}^{b}\pi(k)$$ where $$\pi(k)$$ count the number of primes less or equal to $$k$$, $$a < b$$ are positive integers. The expression I am looking for must involve $$\pi(b)$$, $$\pi(a)$$ and probably $$\pi(b)-\pi(a)$$.

We can use the Prime Number Theorem or the fact that $$\pi(k)=\frac{k}{\log(k)}\left(1+\frac{1}{\log(k)}+\frac{2}{\log^2(k)} + O\left(\frac{1}{\log^3(k)}\right)\right)$$ Then use Euler-Mcllaurin sum formula to get a value with leading term as a function of $$a$$ and $$b$$ or use one of the upper and lower bounds known for $$\pi(k)$$ see Theorem 6.9 of Dussart's paper https://arxiv.org/pdf/1002.0442.pdf and also get bounds involving only $$a$$ and $$b$$. Any help or insight would be much appreciated

• You might as well ask for a formula for the prime sum sequence $S(n)=\pi(1)+\pi(2)+\cdots+\pi(n)$ of oeis.org/A034387 since your sum is $S(b)-S(a-1)$. There are asymptotic formulas for $S(n)$ at its OEIS entry but no exact formulas. Nov 22, 2021 at 12:55
• Thanks Barry, can you point to any reference where i can find asymptotic formulas for $S(n)$ ? Nov 22, 2021 at 16:33
• The OEIS entry says $S(n)\approx n^2/(2\ln n) + O(n^2 \ln\ln n/\ln^2 n)$ but doesn't give an external reference for the approximation. Nov 22, 2021 at 16:54
• This is the Riemann Stieltjes integral $\int_a^b \pi(t) d \lfloor t \rfloor$. Inserting your favorite approximation or asymptotic for $\pi(t)$ would allow you to extract several main terms with logarithmic error terms, or better if you assume RH-type results or better zero-free regions. To understand the integral against $d \lfloor t \rfloor$, I'll note that you can use $\lfloor t \rfloor = t - \{ t \}$, where here $\{ \cdot \}$ is the fractional part. This argument is very similar to some proofs of Euler Maclaurin, and asymptotics follow that path. Nov 22, 2021 at 17:38
• Thank you guys, Nov 22, 2021 at 22:42

Suppose that there are $$m$$ prime numbers between $$a$$ and $$b$$ such that $$a, and suppose that $$a$$ and $$b$$ are both composite numbers. Note that $$m=\pi(b)-\pi(a)$$. Then we have: $$\sum_{i=a}^b\pi(i)=\sum_{i=a}^{p_1-1}\pi(i)+\sum_{k=1}^{m-1}\sum_{i=p_k}^{p_{k+1}-1}\pi(i)+\sum_{i=p_m}^b\pi(i)$$ in all the intervals $$[a,p_1[$$, $$[p_{i-1},p_i[$$ for $$k=2,\ldots, m$$ and $$[p_m,b]$$ the function $$\pi(x)$$ is constant, so that we have $$\sum_{i=a}^{b}\pi(i)=(p_1-a)\pi(a)+\sum_{i=1}^{m-1}(p_{i+1}-p_i)\pi(i)+(b-p_m+1)\pi(b)$$ note also that we have $$\pi(p_i)=\pi(a)+i$$, therefore we get $$\sum_{i=a}^{b}\pi(i)=(p_1-a)\pi(a)+(b-p_m+1)\pi(b)+(p_m-p_1)\pi(a)+\sum_{i=1}^{m-1}(p_{i+1}-p_i)i$$ summing by parts the last term of the RHS gives $$\sum_{i=1}^{m-1}(p_{i+1}-p_i)i=(m-1)p_m-\sum_{i=1}^{m-1}p_i$$ which give the desired expression $$\sum_{i=a}^{b}\pi(i)=(b-a+1)\pi(a)+(b+1)\left(\pi(b)-\pi(a)\right)-\sum_{i=1}^{\pi(b)-\pi(a)}p_i$$ but this does not help solving my actual problem ! thank you guys