Logarithmic time integer division using bit shift addition and subtraction only
问题 I was asked to implement integer division with logarithmic time complexity using only bit shifts, additions and subtractions. I can see how I can deal with a divisor which is a power of 2, but how can I deal with an odd divisor, such that the time remains logarithmic? Is it even possible? EDIT: a way to do it in a time complexity that isn't logarithmic but still better than linear will also be welcomed. Thanks 回答1: It's just like doing long division on paper but in binary. You shift bits from