# Difference between revisions of "Modular arithmetic/Introduction"

m (→The Natural Appeal of Modular Arithmetic) |
(taking out the overlines) |
||

Line 112: | Line 112: | ||

We could (in theory) solve this problem by trying to compute <math>7^{1942}</math>, but this would be extremely time-consuming. Moreover, it would give us much more information than we need. Since we want only the tens and units digits of the number in question, it suffices to find the remainder when the number is divided by <math>100</math>. In other words, all of the information we need can be found using arithmetic mod <math>100</math>. | We could (in theory) solve this problem by trying to compute <math>7^{1942}</math>, but this would be extremely time-consuming. Moreover, it would give us much more information than we need. Since we want only the tens and units digits of the number in question, it suffices to find the remainder when the number is divided by <math>100</math>. In other words, all of the information we need can be found using arithmetic mod <math>100</math>. | ||

− | We begin by writing down the first few powers of <math> | + | We begin by writing down the first few powers of <math>7</math> mod <math>100</math>: |

− | <math> | + | <math>7, 49, 43, 1, 7, 49, 43, 1, \ldots</math> |

A pattern emerges! We see that <math>7^4 = 2401 \equiv 1</math> (mod <math>100</math>). So for any positive integer <math>k</math>, we have <math>7^{4k} = (7^4)^k \equiv 1^k \equiv 1</math> (mod <math>100</math>). In particular, we can write | A pattern emerges! We see that <math>7^4 = 2401 \equiv 1</math> (mod <math>100</math>). So for any positive integer <math>k</math>, we have <math>7^{4k} = (7^4)^k \equiv 1^k \equiv 1</math> (mod <math>100</math>). In particular, we can write | ||

Line 132: | Line 132: | ||

''What are the tens and units digits of <math>13^{404}</math>?'' | ''What are the tens and units digits of <math>13^{404}</math>?'' | ||

− | Again, we will solve this problem by computing <math> | + | Again, we will solve this problem by computing <math>13^{404}</math> modulo <math>100</math>. The first few powers of <math>13</math> mod <math>100</math> are |

− | <math> | + | <math>13, 69, 97, 61, 93, \ldots</math> |

− | This time, no pattern jumps out at us. Is there a way we can find the <math>404^{th}</math> power of <math> | + | This time, no pattern jumps out at us. Is there a way we can find the <math>404^{th}</math> power of <math>13</math> mod <math>100</math> without taking this list all the way out to the <math>404^{th}</math> term -- or even without patiently waiting for the list to yield a pattern? |

− | Suppose we condense the list we started above; and instead of writing down all powers of <math> | + | Suppose we condense the list we started above; and instead of writing down all powers of <math>13</math> mod <math>100</math>, we write only the powers <math>13^k</math>, where <math>k</math> is a power of <math>2</math>. We have the following (all congruences are modulo <math>100</math>): |

− | <math> | + | <math>13^1 = 13</math> |

− | <math> | + | <math>13^2 \equiv 69</math> |

− | <math> | + | <math>13^4 \equiv 69^2 \equiv 61</math> |

− | <math> | + | <math>13^8 \equiv 61^2 \equiv 21</math> |

− | <math> | + | <math>13^{16} \equiv 21^2 \equiv 41</math> |

− | <math> | + | <math>13^{32} \equiv 41^2 \equiv 81</math> |

− | <math> | + | <math>13^{64} \equiv 81^2 \equiv 61</math> |

− | <math> | + | <math>13^{128} \equiv 61^2 \equiv 21</math> |

− | <math> | + | <math>13^{256} \equiv 21^2 \equiv 41</math> |

(Observe that this process yields a pattern of its own, if we carry it out far enough!) | (Observe that this process yields a pattern of its own, if we carry it out far enough!) | ||

Line 166: | Line 166: | ||

We can now use this powers-of-two expansion to compute <math>\overline{13}^{404}</math>: | We can now use this powers-of-two expansion to compute <math>\overline{13}^{404}</math>: | ||

− | <math> | + | <math>13^{404} = 13^{256} \cdot 13^{128} \cdot 13^{16} \cdot 13^4 \equiv 41 \cdot 21 \cdot 41 \cdot 61 \equiv 61.</math> |

So the tens and units digits of <math>13^{404}</math> are <math>6</math> and <math>1</math>, respectively. | So the tens and units digits of <math>13^{404}</math> are <math>6</math> and <math>1</math>, respectively. | ||

− | We can use this method to compute <math>M^e</math> modulo <math>n</math>, for any integers <math>M</math> and <math>e</math>, with <math>e > 0</math>. The beauty of this algorithm is that the process takes, at most, approximately <math>2 \log_2 e</math> steps -- at most <math>\log_2 e</math> steps to compute the values <math> | + | We can use this method to compute <math>M^e</math> modulo <math>n</math>, for any integers <math>M</math> and <math>e</math>, with <math>e > 0</math>. The beauty of this algorithm is that the process takes, at most, approximately <math>2 \log_2 e</math> steps -- at most <math>\log_2 e</math> steps to compute the values <math>M^k</math> modulo <math>n</math> for <math>k</math> a power of two less than <math>e</math>, and at most <math>\log_2 e</math> steps to multiply the appropriate powers of <math>M</math> according to the binary representation of <math>e</math>. |

This method can be further refined using [[Euler's Totient Theorem]]. | This method can be further refined using [[Euler's Totient Theorem]]. | ||

− | |||

− | |||

== Applications of Modular Arithmetic == | == Applications of Modular Arithmetic == |

## Revision as of 00:25, 29 June 2006

**Modular arithmetic** is a special type of arithmetic that involves only integers.

## Contents

## The Basic Idea

Let's use a clock as an example, except let's replace the at the top of the clock with a . Starting at noon, the hour hand points in order to the following:

This is the way in which we count in **modulo 12**. When we add to , we arrive back at . The same is true in any other modulus (modular arithmetic system). In modulo , we count

We can also count backwards in modulo 5. Any time we subtract 1 from 0, we get 4. So, the integers from to , when written in modulo 5, are

where is the same as in modulo 5. Because all integers can be expressed as , , , , or in modulo 5, we give these give integers their own name: the modulo 5 ** residues**. In general, for a natural number that is greater than 1, the modulo residues are the integers that are whole numbers less than :

This just relates each integer to its remainder from the Division Theorem. While this may not seem all that useful at first, counting in this way can help us solve an enormous array of number theory problems much more easily!

## Congruence

There is a mathematical way of saying that all of the integers are the same as one of the modulo 5 residues. For instance, we say that 7 and 2 are **congruent** modulo 5. We write this using the symbol :

The **(mod 5)** part just tells us that we are working with the integers modulo 5. In modulo 5, two integers are congruent when their difference is a multiple of 5. Thus each of the following integers is congruent modulo 5:

In general, two integers and are congruent modulo when is a multiple of . In other words, when is an integer. Otherwise, , which means that and are **not congruent** modulo .

### Examples

- because is a multiple of

- because , which is an integer.

- because , which is not a multiple of .

- because , which is not an integer.

### Sample Problem

Find the modulo residue of .

#### Solution:

Since R , we know that

and is the modulo residue of .

## Arithmetic Modulo n

### Useful Facts

Consider four integers and a positive integer such that and . In modular arithmetic, the following identities hold:

- Addition: .
- Subtraction: .
- Multiplication: .
- Division: , where is a positive integer that divides and .
- Exponentiation: where is a positive integer.

### The Natural Appeal of Modular Arithmetic

Observe that we use modular arithmetic even when solving some of the most basic, everyday problems. For example:

*Cody is cramming for an exam that will be held at 2 PM. It is the morning of the day of the exam, and Cody did not get any sleep during the night. He knows that it will take him exactly one hour to get to school from the time he wakes up, and he insists upon getting at least five hours of sleep. At what time in the morning should Cody stop studying and go to sleep?*

We know that the hours of the day are numbered from to , with hours having the same number if and only if they are a multiple of hours apart. So we can use subtraction mod to answer this question.

We know that since Cody needs five hours of sleep plus one hour to get to school, he must stop studying six hours before the exam. We can find out what time this is by performing the subtraction

.

So Cody must quit studying at 8 AM.

Of course, we are able to perform calculations like this routinely without a formal understanding of modular arithmetic. One reason for this is that the way we keep time gives us a natural model for addition and subtraction in : a "number circle." Just as we model addition and subtraction by moving along a number line, we can model addition and subtraction mod by moving along the circumference of a circle. Even though most of us never learn about modular arithmetic in school, we master this computational model at a very early age.

#### A Word of Caution

Because of the way we define operations in , it is important to check that these operations are well-defined. This is because each of the sets that make up contains many different numbers, and therefore has many different names. For example, observe that in , we have and . It is reasonable to expect that if we perform the addition , we should get the same answer as if we compute , since we are simply using different names for the same objects. Indeed, the first addition yields the sum , which is the same as the result of the second addition.

The "Useful Facts" above are the key to understanding why our operations yield the same results even when we use different names for the same sets. The task of checking that an operation or function is well-defined, is one of the most important basic techniques in abstract algebra.

### Computation of Powers Mod n

The "exponentiation" property given above allows us to perform rapid calculations modulo . Consider, for example, the problem

*What are the tens and units digits of ?*

We could (in theory) solve this problem by trying to compute , but this would be extremely time-consuming. Moreover, it would give us much more information than we need. Since we want only the tens and units digits of the number in question, it suffices to find the remainder when the number is divided by . In other words, all of the information we need can be found using arithmetic mod .

We begin by writing down the first few powers of mod :

A pattern emerges! We see that (mod ). So for any positive integer , we have (mod ). In particular, we can write

(mod ).

By the "multiplication" property above, then, it follows that

(mod ).

Therefore, by the definition of congruence, differs from by a multiple of . Since both integers are positive, this means that they share the same tens and units digits. Those digits are and , respectively.

#### A General Algorithm

In the example above, we were fortunate to find a power of -- namely, -- that is congruent to mod . What if we aren't this lucky? Suppose we want to solve the following problem:

*What are the tens and units digits of ?*

Again, we will solve this problem by computing modulo . The first few powers of mod are

This time, no pattern jumps out at us. Is there a way we can find the power of mod without taking this list all the way out to the term -- or even without patiently waiting for the list to yield a pattern?

Suppose we condense the list we started above; and instead of writing down all powers of mod , we write only the powers , where is a power of . We have the following (all congruences are modulo ):

(Observe that this process yields a pattern of its own, if we carry it out far enough!)

Now, observe that, like any positive integer, can be written as a sum of powers of two:

We can now use this powers-of-two expansion to compute :

So the tens and units digits of are and , respectively.

We can use this method to compute modulo , for any integers and , with . The beauty of this algorithm is that the process takes, at most, approximately steps -- at most steps to compute the values modulo for a power of two less than , and at most steps to multiply the appropriate powers of according to the binary representation of .

This method can be further refined using Euler's Totient Theorem.

## Applications of Modular Arithmetic

Modular arithmetic is an extremely flexible problem solving tool. The following topics are just a few applications and extensions of its use:

## Resources

- The AoPS Introduction to Number Theory by Mathew Crawford.