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 ) : NEW_LINE INDENT num = pow ( 2 , k - 1 ) NEW_LINE if ( num >= N ) : NEW_LINE INDENT print ( " A " , end = " " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " B " , end = " " ) NEW_LINE N -= num NEW_LINE DEDENT k -= 1 NEW_LINE DEDENT