Monday 21 April 2014

Exponentiation mod n

Sometimes it can be hard to obtain information about large numbers because of the complexity of multiplication and division. For example 6711 is the 21 digit number 122130132904968017083 which can't be held accurately in a handheld calculator. If you wanted to determine whether 41 divided this number you would probably have to attempt this by long division. However, modular arithmetic offers a neat way round these problems.

Firstly we determine the remainder when 67 is divided by 41. We find that 67=1x41+26 and so the remainder is 26 and so we can write 67≡26 (mod 41). Now the neat trick of modular arithmetic is that the remainder on dividing 6711 by 41 is the same as the remainder on dividing 2611 by 41. However, rather than doing this in one go, we do it in bite-size chunks using repeated squaring to make the maths easier. So,  672≡262 (mod 41) and since 262 is 676 and 676=16x41+20 then 672≡20 (mod 41). Carrying on in a similar vein we have (672)2=674≡202 (mod 41) and as 202=400=9x41+31 then 674≡31 (mod 41). Further (674)2=678≡312 (mod 41) and as 312=961=23x41+18 then 678≡18 (mod 41).

Squaring any further doesn't help us as the index becomes 2x8=16 which is greater than 11. However as 6711=678x673 we can continue by working out the remainder when 673 is divided by 41 and multiplying this by the remainder when 678 is divided by 41, which we have just worked out. Previously we saw that 672≡20 (mod 41) and 67≡26 (mod 41) and so 673=672x67≡20x26 (mod 41). Now 20x26=520=12x41+28 and so 673≡28 (mod 41). Hence 6711≡18x28=504≡12 (mod 41) since 504=12x41+12.

Thus in answer to our original question 41 doesn't divide 122130132904968017083 as it leaves remainder 12.

This process of reducing a large division into a series of smaller steps using modular arithmetic lends itself well to computation on a programmable calculator. In particular, reducing the index by successive applications of repeated squaring is a fast way to obtain the remainder when a number can be expressed as a number raised to some power.

No comments:

Post a Comment