While reading the text Introduction to Algorithms by Cormen et. al. I came across a few mathematical step which I felt like proving in a more detailed manner, as I could not get steps of the mathematics which they did in short.
Below is the excerpt from the text.
$$c_i = \begin{cases} i &\quad\text{if $i-1$ is an exact power of $2$ }\\ 1&\quad\text{otherwise.}\\ \end{cases}$$
So,
$$\sum_{i=1}^{n}c_i\leq n+\sum_{j=0}^{\lfloor lg(n) \rfloor}2^j\tag 1$$ $$<n+2n=3n$$
The following is my attempt to understand the step $(1)$
$$\sum_{i=1}^{n}c_i=\sum_{\text{$i-1$ is a power of 2}}c_i +\sum_{\text{$i-1$ is not a power of 2}}c_i $$
$$=\sum_{\text{$j$ is a power of 2}}(j+1) +\sum_{\text{$j$ is not a power of 2}}(1) ,\quad\quad\text{where $j=i-1$}$$
$$=\sum_{\text{$j$ is a power of 2}}(j) +\sum_{\forall j}(1) = \left (\sum_{\text{$j$ is a power of 2}}j\right )+n \tag 2$$
$$\text{where $0\leq j \leq n-1$}$$
for the situation in which $j$ is power of $2$ let $2^k$ be the maximum possible value of $j$. So,
$$2^k=n-1 \implies k=\lfloor \log_2(n-1) \rfloor$$
Now we know,
$$n-1<n \implies \log_2(n-1)<\log_2(n) \implies \lfloor\log_2(n-1)\rfloor\leq\lfloor\log_2(n)\rfloor \tag3$$
Let $j=2^t$ , $t=0$ to $k$
So from $(2)$ and $(3)$ we have,
$$\sum_{i=1}^{n}c_i\leq n+\sum_{t=0}^{\lfloor lg(n) \rfloor}2^t \tag 4$$
The step which the authors achieved directly in $(1)$ took me so many steps to understand or derive in $(4)$. Is there a shorter method available or some intuition which the authors used to achieve the result directly?