PreCompute and store the powers of 2
List < int > powersOfTwo = new List < int > ( ) ; powersOfTwo . Add ( 1 ) ; for ( int i = 1 ; i < 11 ; i ++ ) { powersOfTwo . Add ( powersOfTwo [ i - 1 ] * 2 ) ; } int ctr = 1 ; int ans = 0 ; while ( N > 0 ) {