(∑_(i=1)^n)i×(2^i)

(∑_(i=1)^(Log2[M]-1))i×(2^i)

(∑_(i=1)^(⌊Log2[M]⌋-1))i×(2^i)+⌊Log2[M]⌋×(M-(2^(⌊Log2[M]⌋))+1)

2-(2^(1+⌊Log2[M]⌋))+(2^(⌊Log2[M]⌋)) ⌊Log2[M]⌋+(1-(2^(⌊Log2[M]⌋))+M) ⌊Log2[M]⌋

2-(2^(1+⌊Log2[M]⌋))+(2^(⌊Log2[M]⌋)) ⌊Log2[M]⌋+1⌊Log2[M]⌋-(2^(⌊Log2[M]⌋))⌊Log2[M]⌋+M⌊Log2[M]⌋

2-(2^(1+⌊Log2[M]⌋))+(2^(⌊Log2[M]⌋)) ⌊Log2[M]⌋+⌊Log2[M]⌋-(2^(⌊Log2[M]⌋))⌊Log2[M]⌋+M⌊Log2[M]⌋

2-(2^(1+⌊Log2[M]⌋))+⌊Log2[M]⌋+M⌊Log2[M]⌋

2-(2^(1+⌊Log2[M]⌋))+(M+1)⌊Log2[M]⌋