Compute remainders from right to left when divided by ' b '
vector < int > rl ( len + 1 , 0 ) ; rl [ len - 1 ] = ( str [ len - 1 ] - '0' ) % b ; int power10 = 10 ; for ( int i = len - 2 ; i >= 0 ; i -- ) { rl [ i ] = ( rl [ i + 1 ] + ( str [ i ] - '0' ) * power10 ) % b ; power10 = ( power10 * 10 ) % b ; }