At a particular time , we have to decide whether we have to print ' A ' or ' B ' , this can be check by calculating the value of pow ( 2 , k - 1 )
while ( k > 0 ) { num = pow ( 2 , k - 1 ) ; if ( num >= N ) cout << " A " ; else { cout << " B " ; N -= num ; } k -- ; }