Sum of series with binary parity in the numerator

I'm now stuck with this question, and I don't even know where to start: Find sum of series$$\sum_1^\infty \frac{f(n)}{n(n+1)}$$, where f(n) - number of ones in binary representation of n.

I wish I could post some moves, that I've tried but I don't know what to do.

Thanks!


Solution 1:

Maybe there is a quicker way, but here is one. Let the sum be $S$. We have $$\frac{f(n)}{n(n+1)} = \frac{f(n)}{n}-\frac{f(n)}{n+1}$$ $$\implies \frac{f(2n)}{(2n)(2n+1)}+\frac{f(2n+1)}{(2n+1)(2n+2)} = \frac{f(2n)}{2n}-\frac{f(2n)-f(2n+1)}{2n+1}-\frac{f(2n+1)}{2n+2}$$

Now $f(2n+1) = f(2n)+1, \; f(2n) = f(n)$, so we can write: $$\frac{f(2n)}{(2n)(2n+1)}+\frac{f(2n+1)}{(2n+1)(2n+2)} = \frac{f(2n)}{2n}+\frac1{2n+1}-\frac{f(2n)+1}{2n+2} \\ = \frac12\left(\frac{f(n)}n -\frac{f(n)}{n+1}\right)+\left(\frac1{2n+1}-\frac1{2n+2}\right)$$

$$\implies S = \frac12+ \frac12\sum_{n=1}^\infty \frac{f(n)}{n(n+1)}+\sum_{n=1}^\infty \left(\frac1{2n+1}-\frac1{2n+2}\right) $$ $$\implies 2S = 1 + S + 2\log 2 -1 \implies S = 2\log 2 \approx 1.386$$

Solution 2:

Code:

double sum=0;
for(int i=1;i<9999999;i++){
    double s2=Integer.bitCount(i);
    sum+=(s2)/(i*(i+1));
}

Output Data

$$\begin{array}{r|l} n&\sum\\\hline 9&1.065079365079365\\ 99&1.3394382621894894\\ 999&1.3800972409478014\\ 9999&1.3854974129587205\\ 99999&1.3852676077956714\\&(\text{limit of data type, therefore decreased value}) \end{array}$$