Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
we take the divisor and add it to ourselves (i.e. multiply by 2), then add the resulting number again .. until the result becomes greater than the divisible number (we don’t remember this amount, we take the previous one)
then choose:
* from the difference of the dividend and the current sum, subtract the divisor in the loop until the result becomes less than zero (the previous one will be the remainder)
* in the process of calculating the sum of the divisor, intermediate results (an array of n elements, each y * 2 * n) subtract the previous sum from the difference of the dividend, if the result is less than zero, do not remember the result and move on to the next subtotal, until we have gone through all the saved sums. The last thing we try to subtract is the divisor itself.
this algorithm is noticeably more efficient than just stupid divisor subtraction, the second option is even more efficient but consumes log(x) memory
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question