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