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
 A: Suppose that there are $m$ prime numbers between $a$ and $b$ such that $a<p_1<p_2<\ldots < p_m<b$, 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
