Explanation of right to left binary method of modular arithmetic?
问题 I have been studying this link from wikipedia of modulo of a large number, Here is the pseudocode. function modular_pow(base, exponent, modulus) result := 1 while exponent > 0 if (exponent mod 2 == 1): result := (result * base) mod modulus exponent := exponent >> 1 base = (base * base) mod modulus return result I don't understand the explanation given in wiki.Why I have to check if exp%2 is even or odd. also why I am doing the three operations? 回答1: This algorithm is a combination of the