title: Finding the total number of set-bits from 1 to n
body: <p>Write an algorithm to find <code>F(n)</code> the number of bits set to 1, in all numbers from 1 to n for any given value of n.</p>
  
  <p>Complexity should be <code>O(log n)</code></p>
  
  <p>For example:</p>
  
  <pre><code>1: 001
  2: 010
  3: 011
  4: 100
  5: 101
  6: 110
  </code></pre>
  
  <p>So</p>
  
  <pre><code>F(1) = 1,  
  F(2) = F(1) + 1 = 2,
  F(3) = F(2) + 2 = 4,
  F(4) = F(3) + 1 = 5,
  etc.
  </code></pre>
  
  <p>I can only design an <code>O(n)</code> algorithm.</p>