Question: 
Write a python function to count the total set bits from 1 to n.


Model's Code:
def count_Set_Bits(n):
    count = 0
    for i in range(1, n + 1):
        count += bin(i).count('1')
    return count



Sample Correct Code:
def count_Set_Bits(n) :  
    n += 1; 
    powerOf2 = 2;   
    cnt = n // 2;  
    while (powerOf2 <= n) : 
        totalPairs = n // powerOf2;  
        cnt += (totalPairs // 2) * powerOf2;  
        if (totalPairs & 1) : 
            cnt += (n % powerOf2) 
        else : 
            cnt += 0
        powerOf2 <<= 1;    
    return cnt;  


Asserts:
assert count_Set_Bits(16) == 33
assert count_Set_Bits(2) == 2
assert count_Set_Bits(14) == 28


Tests:
Test 1 of 3: PASS
Test 2 of 3: PASS
Test 3 of 3: PASS

Test 707 of 974: 534/707 (75.53041018387553%): success