algorithm for modular exponentiation
Whereas even for fairly small bases and exponents the results can be too large for calculation with pencil and paper or even with a calculator, there is a fairly simple algorithm to solve for in the congruence .
Assign , and .
Test if . If not, repeat the previous step.
For example, solve . At the first step we have , and .
At the second step, since is even, we reassign and square 179, which is 32041, and that is 9 modulo 13.
is not zero yet, so we go back to the second step, and is still even, so we halve it to 3. The square of 9 is 81, which is just 3 over 78, the nearest multiple of 13, so now .
On the third iteration of the second step is now odd, so we decrease it to 2 and multiply (which is still 1 right now) by , which is now 3, so now .
On the next iteration of the second step is again even, but with it being 2 either halving it or decrementing sets , though of course we gon on with the halving branch of the algorithm: is still 3, and its square 9 is less than 13.
Now on the las iteration of the second step, is odd so we decrement it down to 0. is 3 (set back on the third iteration of the second step) and 3 times 9 is 27, which is 1 more than twice 13, so now .
In this run of the algorithm four squaring operations were necessary as well as various additions and subtractions, but all this could have easily been accomplished easily either with pencil or paper or with the help of a basic calculator with only a 10-digit display. To actually raise 179 to the 12th power with the necessary accuracy on paper would have required eleven multiplications with plenty of opportunity for errors to creep into the calculation. With Mathematica it is a snap to verify that the answer is 1082022699327332498100696241, and that 83232515332871730623130480 goes into 1082022699327332498100696240 thirteen times, but there are much larger numbers still which would be beyond Mathematica’s range to exponentiate yet which the remainders could easily be obtained with this algorithm.
|Title||algorithm for modular exponentiation|
|Date of creation||2013-03-22 18:09:11|
|Last modified on||2013-03-22 18:09:11|
|Last modified by||PrimeFan (13766)|