https://artofproblemsolving.com/wiki/api.php?action=feedcontributions&user=Mathjoker&feedformat=atomAoPS Wiki - User contributions [en]2024-03-29T07:13:10ZUser contributionsMediaWiki 1.31.1https://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic/Intermediate&diff=5260Modular arithmetic/Intermediate2006-06-29T05:30:25Z<p>Mathjoker: Moved "a word of caution" to its proper home.</p>
<hr />
<div>Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
For examples, see [[Introduction to modular arithmetic]].<br />
<br />
<br />
=== The Integers Modulo n ===<br />
<br />
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements. For example, if <math>n = 3</math>, then the integers are divided into the following sets:<br />
<br />
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math><br />
<br />
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math><br />
<br />
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math><br />
<br />
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).<br />
<br />
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it. For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>. The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third. The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.<br />
<br />
Instead of thinking of the objects <math>\overline{0}</math>, <math>\overline{1}</math>, and <math>\overline{2}</math> as sets, we can treat them as algebraic objects -- like numbers -- with their own operations of addition and multiplication. Together, these objects form '''the integers modulo <math>3</math>,''' or <math>\mathbb{Z}_3</math>. More generally, if <math>n</math> is a positive integer, then we can define<br />
<br />
<math>\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}</math>,<br />
<br />
where for each <math>k</math>, <math>\overline{k}</math> is defined by<br />
<br />
<math>\overline{k} = \{ m \in \mathbb{Z} \mbox{ such that } m \equiv k \pmod{n} \}.</math><br />
<br />
=== Addition, Subtraction, and Multiplication Mod n ===<br />
<br />
We define addition, subtraction, and multiplication in <math>\mathbb{Z}_n</math> according to the following rules:<br />
<br />
<math>\overline{a} + \overline{b} = \overline{a+b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Addition)<br />
<br />
<math>\overline{a} - \overline{b} = \overline{a-b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Subtraction)<br />
<br />
<math>\overline{a} \cdot \overline{b} = \overline{ab}</math> for all <math>a, b \in \mathbb{Z}</math>. (Multiplication)<br />
<br />
So for example, if <math>n = 7</math>, then we have<br />
<br />
<math>\overline{3} + \overline{2} = \overline{3+2} = \overline{5}</math><br />
<br />
<math>\overline{4} + \overline{4} = \overline{4+4} = \overline{8} = \overline{1}</math><br />
<br />
<math>\overline{4} \cdot \overline{3} = \overline{4 \cdot 3} = \overline{12} = \overline{5}</math><br />
<br />
<math>\overline{6} \cdot \overline{6} = \overline{6 \cdot 6} = \overline{36} = \overline{1}</math><br />
<br />
Notice that, in each case, we reduce to an answer of the form <math>\overline{k}</math>, where <math>0 \leq k < 7</math>. We do this for two reasons: to keep possible future calculations as manageable as possible, and to emphasize the point that each expression takes one of only seven (or in general, <math>n</math>) possible values. (Some people find it useful to reduce an answer such as <math>\overline{5}</math> to <math>\overline{-2}</math>, which is negative but has a smaller absolute value.)<br />
<br />
==== A Word of Caution ====<br />
<br />
Because of the way we define operations in <math>\mathbb{Z}_n</math>, it is important to check that these operations are well-defined. This is because each of the sets that make up <math>\mathbb{Z}_n</math> contains many different numbers, and therefore has many different names. For example, observe that in <math>\mathbb{Z}_7</math>, we have <math>\overline{1} = \overline{8}</math> and <math>\overline{2} = \overline{9}</math>. It is reasonable to expect that if we perform the addition <math>\overline{8} + \overline{9}</math>, we should get the same answer as if we compute <math>\overline{1} + \overline{2}</math>, since we are simply using different names for the same objects. Indeed, the first addition yields the sum <math>\overline{17} = \overline{3}</math>, which is the same as the result of the second addition.<br />
<br />
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]].<br />
<br />
== Algebraic Properties of the Integers Mod n ==<br />
<br />
The integers modulo <math>n</math> form an algebraic structure called a [[ring]] -- a structure in which we can add, subtract, and multiply elements.<br />
<br />
Anyone who has taken a high school algebra class is familiar with several examples of rings, including the ring of integers, the ring of rational numbers, and the ring of real numbers. The ring <math>\mathbb{Z}_n</math> has some algebraic features that make it quite different from the more familiar rings listed above.<br />
<br />
First of all, notice that if we choose a nonzero element <math>\overline{a}</math> of <math>\mathbb{Z}_n</math>, and add <math>n</math> copies of this element, we get<br />
<br />
<math>\overline{a} + \overline{a} + \cdots + \overline{a} = n \cdot \overline{a} = \overline{na} = \overline{0}</math>,<br />
<br />
since <math>na</math> is a multiple of <math>n</math>. So it is possible to add several copies of a nonzero element of <math>\mathbb{Z}_n</math> and get zero. This phenomenon, which is called '''torsion''', does not occur in the reals, the rationals, or the integers.<br />
<br />
Another curious feature of <math>\mathbb{Z}_n</math> is that a polynomial over <math>\mathbb{Z}_n</math> can have a number of roots greater than its degree. Consider, for example, the polynomial congruence<br />
<br />
<math>x^2 - 2x - 15 \equiv 0 \pmod{21}</math>.<br />
<br />
We might be tempted to solve this congruence by factoring the expression on the left:<br />
<br />
<math>(x - 5)(x + 3) \equiv 0 \pmod{21}</math>.<br />
<br />
Indeed, this factorization yields two solutions to the congruence: <math>x \equiv 5 \pmod{21}</math>, and <math>x \equiv -3 \equiv 18 \pmod{21}</math>. (Note that two values of <math>x</math> that are congruent modulo <math>21</math> are considered the same solution.)<br />
<br />
However, since <math>15 \equiv 99 \pmod{21}</math>, the original congruence is equivalent to<br />
<br />
<math>x^2 - 2x - 99 \equiv 0 \pmod{21}</math>.<br />
<br />
This time, factoring the expression on the left yields<br />
<br />
<math>(x - 11)(x + 9) \equiv 0 \pmod{21}</math>.<br />
<br />
And we find that there are two more solutions! The values <math>x \equiv 11 \pmod{21}</math> and <math>x \equiv -9 \equiv 12 \pmod{21}</math> both solve the congruence. So our congruence has at least four solutions -- two more than we might expect based on the degree of the polynomial.<br />
<br />
Why do the "rules" of algebra that work so well for the real numbers seem to fail in <math>\mathbb{Z}_{21}</math>? To understand this, let's take a closer look at the congruence<br />
<br />
<math>(x - 5)(x + 3) \equiv 0 \pmod{21}</math>.<br />
<br />
If we were solving this as an equation over the reals, we would immediately conclude that either <math>x - 5</math> must be zero, or <math>x + 3</math> must be zero in order for the product to equal zero. However, this is not the case in <math>\mathbb{Z}_{21}</math>! It is possible to multiply two nonzero elements of <math>\mathbb{Z}_{21}</math> and get zero. For example, we have<br />
<br />
<math>\overline{3} \cdot \overline{7} = \overline{0}</math><br />
<br />
<math>\overline{9} \cdot \overline{7} = \overline{0}</math><br />
<br />
<math>\overline{6} \cdot \overline{14} = \overline{0}</math><br />
<br />
But wait! Suppose we take a close look at this last product, and we set <math>x - 5 \equiv 6 \pmod{21}</math> and <math>x + 3 \equiv 14 \pmod{21}</math>. Then we have <math>x \equiv 11 \pmod{21}</math> -- another of the solutions of our congruence! (One can check that the other two factorizations don't lead to any valid solutions; however, there are many other factorizations of zero that need to be checked.)<br />
<br />
In the ring of real numbers, it is a well-known fact that if <math>ab = 0</math>, then <math>a = 0</math> or <math>b = 0</math>. For this reason, we call the ring of real numbers a '''domain'''. However, a similar fact does ''not'' apply in general in <math>\mathbb{Z}_n</math>; therefore, <math>\mathbb{Z}_n</math> is not in general a domain.<br />
<br />
<br />
<br />
== Topics ==<br />
The following topics expand on the flexible nature of modular arithmetic as a problem solving tool:<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).<br />
<br />
<br />
An example exercise with modular arithmetic:<br />
<br />
'''Problem:'''<br />
<br />
Let <br />
<br />
<math>D=d_1d_2d_3d_4d_5d_6d_7d_8d_9</math> <br />
<br />
be a nine-digit positive integer (each digit not necessarily distinct). Consider <br />
<br />
<math>E=e_1e_2e_3e_4e_5e_6e_7e_8e_9</math>,<br />
<br />
another nine-digit positive integer with the property that each digit ei when substituted for di makes the<br />
modified D divisible by 7. Let <br />
<br />
<math>F=f_1f_2f_3f_4f_5f_6f_7f_8f_9</math> be a third nine-digit positive integer with the same relation to E as E has to D.<br />
<br />
Prove that every <math>di - fi</math> is divisible by 7. <br />
<br />
<br />
<br />
'''Solution:'''<br />
<br />
Any positive integer <math>D=d_1d_2d_3d_4d_5d_6d_7d_8d_9</math> can be expressed <math>(10^8)d_1+(10^7)d_2+...(10^0)d_9</math>.<br />
<br />
Since '''10=3 mod 7''', and since it holds that if '''a=b mod c''' then <math>a^n=b^n</math> '''mod c''', then D can be expressed much more simply mod 7; that is,<br />
<math>D= 2d1 +3d2 +1d3 -2d4 -3d5 -d6 +2d7 +3d8 +d9 </math>= '''x mod 7'''.<br />
<br />
Each number in E must make the modified D equal 0 mod 7, so for each <math>d_i</math>, <math>e_i = \frac{x+7k}{c}-d_i</math>, where c is the coefficient of <math>d_i</math> <br />
and k is an element of {-2,-1,0,1,2}. The patient reader should feel free to verify that this makes '''D = 0 mod 7'''.<br />
<br />
In terms of <math>d_i</math> terms, then, we find each <math>c_ie_i = x - c_id_i + 7k</math>.<br />
<br />
Then <math>E= 2e_1 +3e_2 +1e_3 -2e_4 -3e_5 -e_6 +2e_7 +3e_8 +e_9</math> '''mod 7''' can be expressed<br />
<math>E= (x-2d_1)+(x-3d_2)+(x-d_3)+...+(x-d_9) = (9x)-D</math> '''mod 7 = (9x)- x = 8x = x mod 7'''.<br />
(note that the 7s, which do not change the mod value, have been eliminated).<br />
<br />
Each number in F must make the modified E equal '''0 mod 7''', so for each <math>e_i</math>, <math>f_i = \frac{x+7k_2}{c_i} -e_i = \frac{x+7k_2}{c_i} - (\frac{x+7k_1}{c_i} -d_i)</math>.<br />
<br />
By design and selection of k, all <math>(f_i)</math> are integers, and <math>d_i - f_i</math> is always an integer because it is the difference of two integers.<br />
<br />
<math>d_i - f_i = \frac{7k_2-7k_1}{c_i}</math><br />
<br />
<math>c_i</math> is a member of the set {1, 2, 3}. Since no <math>c_i</math> divides 7, 7 may be factored and <math>7\frac{k_2-k_1}{c_i} = d_i - f_i</math> is the product of two integers.<br />
<br />
Let <math>A=\frac{k_2-k_1}{c_i}</math> then <math>d_i - f_i =</math> '''7A mod 7 = 0 mod 7''' for all <math>(d_i,f_i)</math>, QED.<br />
<br />
<br />
<br />
== Resources ==<br />
* [http://www.artofproblemsolving.com/Resources/Papers/SatoNT.pdf Number Theory Problems and Notes] by [[Naoki Sato]].<br />
<br />
<br />
<br />
<br />
== See also ==<br />
* [[Introduction to modular arithmetic]]<br />
* [[Olympiad modular arithmetic]]</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic/Introduction&diff=5259Modular arithmetic/Introduction2006-06-29T05:29:37Z<p>Mathjoker: /* Arithmetic Modulo n */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]].<br />
<br />
<br />
<br />
== The Basic Idea ==<br />
Let's use a clock as an example, except let's replace the <math>\displaystyle 12</math> at the top of the clock with a <math>\displaystyle 0</math>. Starting at noon, the hour hand points in order to the following:<br />
<br />
<br />
<math>\displaystyle 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, \ldots </math><br />
<br />
<br />
This is the way in which we count in '''modulo 12'''. When we add <math>\displaystyle 1</math> to <math>\displaystyle 11</math>, we arrive back at <math>\displaystyle 0</math>. The same is true in any other [[modulus]] (modular arithmetic system). In modulo <math>\displaystyle 5</math>, we [[counting | count]]<br />
<br />
<br />
<math>\displaystyle 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, \ldots</math><br />
<br />
<br />
We can also count backwards in modulo 5. Any time we subtract 1 from 0, we get 4. So, the integers from <math>\displaystyle -12</math> to <math>\displaystyle 0</math>, when written in modulo 5, are<br />
<br />
<br />
<math>\displaystyle 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0,</math><br />
<br />
<br />
where <math>\displaystyle -12</math> is the same as <math>\displaystyle 3</math> in modulo 5. Because all integers can be expressed as <math>\displaystyle 0</math>, <math>\displaystyle 1</math>, <math>\displaystyle 2</math>, <math>\displaystyle 3</math>, or <math>\displaystyle 4</math> in modulo 5, we give these give integers their own name: the modulo 5 '''[[residue | residues]]'''. In general, for a natural number <math>\displaystyle n</math> that is greater than 1, the modulo <math>\displaystyle n</math> residues are the integers that are [[whole number | whole numbers]] less than <math>\displaystyle n</math>:<br />
<br />
<br />
<math>\displaystyle 0, 1, 2, \ldots, n-1. </math><br />
<br />
<br />
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!<br />
<br />
<br />
<br />
== Congruence ==<br />
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 <math>\displaystyle \equiv</math>:<br />
<br />
<br />
<center><math>\displaystyle 7 \equiv 2 \pmod{5}. </math></center><br />
<br />
<br />
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:<br />
<center><math>\displaystyle -12 \equiv -7 \equiv -2 \equiv 3 \equiv 8 \equiv 13 \equiv 18 \equiv 23 \pmod{5} </math></center><br />
In general, two integers <math>\displaystyle a</math> and <math>\displaystyle b</math> are congruent modulo <math>\displaystyle n</math> when <math>\displaystyle a - b</math> is a multiple of <math>\displaystyle n</math>. In other words, <math>\displaystyle a \equiv b \pmod{n}</math> when <math>\displaystyle \frac{a-b}{n}</math> is an integer. Otherwise, <math>\displaystyle a \not\equiv b \pmod{n}</math>, which means that <math>\displaystyle a</math> and <math>\displaystyle b</math> are '''not congruent''' modulo <math>\displaystyle n</math>.<br />
<br />
<br />
<br />
=== Examples ===<br />
* <math>\displaystyle 31 \equiv 1 \pmod{10}</math> because <math>\displaystyle 31 - 1 = 30</math> is a multiple of <math>\displaystyle 10</math><br />
<br />
<br />
* <math>\displaystyle 43 \equiv 22 \pmod{7}</math> because <math>\displaystyle \frac{43 - 22}{7} = \frac{21}{7} = 3</math>, which is an integer.<br />
<br />
<br />
* <math>\displaystyle 8 \not\equiv -8 \pmod{3}</math> because <math>\displaystyle 8 - (-8) = 16</math>, which is not a multiple of <math>\displaystyle 3</math>.<br />
<br />
<br />
* <math>\displaystyle 91 \not\equiv 18 \pmod{6}</math> because <math>\displaystyle \frac{91 - 18}{6} = \frac{73}{6}</math>, which is not an integer.<br />
<br />
<br />
<br />
=== Sample Problem ===<br />
Find the modulo <math>\displaystyle 4</math> residue of <math>\displaystyle 311</math>.<br />
==== Solution: ====<br />
Since <math>\displaystyle 311 \div 4 = 77</math> R <math>\displaystyle 3</math>, we know that <br />
<center><math>\displaystyle 311 \equiv 3 \pmod{4}</math></center><br />
and <math>\displaystyle 3</math> is the modulo <math>\displaystyle 4</math> residue of <math>\displaystyle 311</math>.<br />
<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
<br />
<br />
=== The Natural Appeal of Modular Arithmetic ===<br />
<br />
Observe that we use modular arithmetic even when solving some of the most basic, everyday problems. For example:<br />
<br />
''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?''<br />
<br />
We know that the hours of the day are numbered from <math>1</math> to <math>12</math>, with hours having the same number if and only if they are a multiple of <math>12</math> hours apart. So we can use subtraction mod <math>12</math> to answer this question.<br />
<br />
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<br />
<br />
<math>2 - 6 = -4 \equiv 8 \pmod{12}</math>.<br />
<br />
So Cody must quit studying at 8 AM.<br />
<br />
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 <math>\mathbb{Z}_n</math>: a "number circle." Just as we model addition and subtraction by moving along a number line, we can model addition and subtraction mod <math>n</math> 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.<br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
We begin by writing down the first few powers of <math>7</math> mod <math>100</math>:<br />
<br />
<math>7, 49, 43, 1, 7, 49, 43, 1, \ldots</math><br />
<br />
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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
==== A General Algorithm ====<br />
<br />
In the example above, we were fortunate to find a power of <math>7</math> -- namely, <math>7^4</math> -- that is congruent to <math>1</math> mod <math>100</math>. What if we aren't this lucky? Suppose we want to solve the following problem:<br />
<br />
''What are the tens and units digits of <math>13^{404}</math>?''<br />
<br />
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<br />
<br />
<math>13, 69, 97, 61, 93, \ldots</math><br />
<br />
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?<br />
<br />
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>):<br />
<br />
<math>\displaystyle 13^1 = 13</math><br />
<br />
<math>13^2 \equiv 69</math><br />
<br />
<math>13^4 \equiv 69^2 \equiv 61</math><br />
<br />
<math>13^8 \equiv 61^2 \equiv 21</math><br />
<br />
<math>13^{16} \equiv 21^2 \equiv 41</math><br />
<br />
<math>13^{32} \equiv 41^2 \equiv 81</math><br />
<br />
<math>13^{64} \equiv 81^2 \equiv 61</math><br />
<br />
<math>13^{128} \equiv 61^2 \equiv 21</math><br />
<br />
<math>13^{256} \equiv 21^2 \equiv 41</math><br />
<br />
(Observe that this process yields a pattern of its own, if we carry it out far enough!)<br />
<br />
Now, observe that, like any positive integer, <math>404</math> can be written as a sum of powers of two:<br />
<br />
<math>404 = 256 + 128 + 16 + 4</math><br />
<br />
We can now use this powers-of-two expansion to compute <math>\overline{13}^{404}</math>:<br />
<br />
<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><br />
<br />
So the tens and units digits of <math>13^{404}</math> are <math>6</math> and <math>1</math>, respectively.<br />
<br />
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>.<br />
<br />
This method can be further refined using [[Euler's Totient Theorem]].<br />
<br />
== Applications of Modular Arithmetic ==<br />
Modular arithmetic is an extremely flexible problem solving tool. The following topics are just a few applications and extensions of its use:<br />
* [[Divisibility rules]]<br />
* [[Linear congruence | Linear congruences]]<br />
<br />
<br />
<br />
== Resources ==<br />
* The AoPS [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?page_id=10 Introduction to Number Theory] by [[Mathew Crawford]].<br />
<br />
<br />
== See also ==<br />
* [[Intermediate modular arithmetic]]<br />
* [[Olympiad modular arithmetic]]</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic/Introduction&diff=5258Modular arithmetic/Introduction2006-06-29T05:28:21Z<p>Mathjoker: /* A General Algorithm */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]].<br />
<br />
<br />
<br />
== The Basic Idea ==<br />
Let's use a clock as an example, except let's replace the <math>\displaystyle 12</math> at the top of the clock with a <math>\displaystyle 0</math>. Starting at noon, the hour hand points in order to the following:<br />
<br />
<br />
<math>\displaystyle 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, \ldots </math><br />
<br />
<br />
This is the way in which we count in '''modulo 12'''. When we add <math>\displaystyle 1</math> to <math>\displaystyle 11</math>, we arrive back at <math>\displaystyle 0</math>. The same is true in any other [[modulus]] (modular arithmetic system). In modulo <math>\displaystyle 5</math>, we [[counting | count]]<br />
<br />
<br />
<math>\displaystyle 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, \ldots</math><br />
<br />
<br />
We can also count backwards in modulo 5. Any time we subtract 1 from 0, we get 4. So, the integers from <math>\displaystyle -12</math> to <math>\displaystyle 0</math>, when written in modulo 5, are<br />
<br />
<br />
<math>\displaystyle 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0,</math><br />
<br />
<br />
where <math>\displaystyle -12</math> is the same as <math>\displaystyle 3</math> in modulo 5. Because all integers can be expressed as <math>\displaystyle 0</math>, <math>\displaystyle 1</math>, <math>\displaystyle 2</math>, <math>\displaystyle 3</math>, or <math>\displaystyle 4</math> in modulo 5, we give these give integers their own name: the modulo 5 '''[[residue | residues]]'''. In general, for a natural number <math>\displaystyle n</math> that is greater than 1, the modulo <math>\displaystyle n</math> residues are the integers that are [[whole number | whole numbers]] less than <math>\displaystyle n</math>:<br />
<br />
<br />
<math>\displaystyle 0, 1, 2, \ldots, n-1. </math><br />
<br />
<br />
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!<br />
<br />
<br />
<br />
== Congruence ==<br />
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 <math>\displaystyle \equiv</math>:<br />
<br />
<br />
<center><math>\displaystyle 7 \equiv 2 \pmod{5}. </math></center><br />
<br />
<br />
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:<br />
<center><math>\displaystyle -12 \equiv -7 \equiv -2 \equiv 3 \equiv 8 \equiv 13 \equiv 18 \equiv 23 \pmod{5} </math></center><br />
In general, two integers <math>\displaystyle a</math> and <math>\displaystyle b</math> are congruent modulo <math>\displaystyle n</math> when <math>\displaystyle a - b</math> is a multiple of <math>\displaystyle n</math>. In other words, <math>\displaystyle a \equiv b \pmod{n}</math> when <math>\displaystyle \frac{a-b}{n}</math> is an integer. Otherwise, <math>\displaystyle a \not\equiv b \pmod{n}</math>, which means that <math>\displaystyle a</math> and <math>\displaystyle b</math> are '''not congruent''' modulo <math>\displaystyle n</math>.<br />
<br />
<br />
<br />
=== Examples ===<br />
* <math>\displaystyle 31 \equiv 1 \pmod{10}</math> because <math>\displaystyle 31 - 1 = 30</math> is a multiple of <math>\displaystyle 10</math><br />
<br />
<br />
* <math>\displaystyle 43 \equiv 22 \pmod{7}</math> because <math>\displaystyle \frac{43 - 22}{7} = \frac{21}{7} = 3</math>, which is an integer.<br />
<br />
<br />
* <math>\displaystyle 8 \not\equiv -8 \pmod{3}</math> because <math>\displaystyle 8 - (-8) = 16</math>, which is not a multiple of <math>\displaystyle 3</math>.<br />
<br />
<br />
* <math>\displaystyle 91 \not\equiv 18 \pmod{6}</math> because <math>\displaystyle \frac{91 - 18}{6} = \frac{73}{6}</math>, which is not an integer.<br />
<br />
<br />
<br />
=== Sample Problem ===<br />
Find the modulo <math>\displaystyle 4</math> residue of <math>\displaystyle 311</math>.<br />
==== Solution: ====<br />
Since <math>\displaystyle 311 \div 4 = 77</math> R <math>\displaystyle 3</math>, we know that <br />
<center><math>\displaystyle 311 \equiv 3 \pmod{4}</math></center><br />
and <math>\displaystyle 3</math> is the modulo <math>\displaystyle 4</math> residue of <math>\displaystyle 311</math>.<br />
<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
<br />
<br />
=== The Natural Appeal of Modular Arithmetic ===<br />
<br />
Observe that we use modular arithmetic even when solving some of the most basic, everyday problems. For example:<br />
<br />
''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?''<br />
<br />
We know that the hours of the day are numbered from <math>1</math> to <math>12</math>, with hours having the same number if and only if they are a multiple of <math>12</math> hours apart. So we can use subtraction mod <math>12</math> to answer this question.<br />
<br />
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<br />
<br />
<math>2 - 6 = -4 \equiv 8 \pmod{12}</math>.<br />
<br />
So Cody must quit studying at 8 AM.<br />
<br />
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 <math>\mathbb{Z}_n</math>: a "number circle." Just as we model addition and subtraction by moving along a number line, we can model addition and subtraction mod <math>n</math> 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.<br />
<br />
==== A Word of Caution ====<br />
<br />
Because of the way we define operations in <math>\mathbb{Z}_n</math>, it is important to check that these operations are well-defined. This is because each of the sets that make up <math>\mathbb{Z}_n</math> contains many different numbers, and therefore has many different names. For example, observe that in <math>\mathbb{Z}_7</math>, we have <math>\overline{1} = \overline{8}</math> and <math>\overline{2} = \overline{9}</math>. It is reasonable to expect that if we perform the addition <math>\overline{8} + \overline{9}</math>, we should get the same answer as if we compute <math>\overline{1} + \overline{2}</math>, since we are simply using different names for the same objects. Indeed, the first addition yields the sum <math>\overline{17} = \overline{3}</math>, which is the same as the result of the second addition.<br />
<br />
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]].<br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
We begin by writing down the first few powers of <math>7</math> mod <math>100</math>:<br />
<br />
<math>7, 49, 43, 1, 7, 49, 43, 1, \ldots</math><br />
<br />
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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
==== A General Algorithm ====<br />
<br />
In the example above, we were fortunate to find a power of <math>7</math> -- namely, <math>7^4</math> -- that is congruent to <math>1</math> mod <math>100</math>. What if we aren't this lucky? Suppose we want to solve the following problem:<br />
<br />
''What are the tens and units digits of <math>13^{404}</math>?''<br />
<br />
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<br />
<br />
<math>13, 69, 97, 61, 93, \ldots</math><br />
<br />
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?<br />
<br />
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>):<br />
<br />
<math>\displaystyle 13^1 = 13</math><br />
<br />
<math>13^2 \equiv 69</math><br />
<br />
<math>13^4 \equiv 69^2 \equiv 61</math><br />
<br />
<math>13^8 \equiv 61^2 \equiv 21</math><br />
<br />
<math>13^{16} \equiv 21^2 \equiv 41</math><br />
<br />
<math>13^{32} \equiv 41^2 \equiv 81</math><br />
<br />
<math>13^{64} \equiv 81^2 \equiv 61</math><br />
<br />
<math>13^{128} \equiv 61^2 \equiv 21</math><br />
<br />
<math>13^{256} \equiv 21^2 \equiv 41</math><br />
<br />
(Observe that this process yields a pattern of its own, if we carry it out far enough!)<br />
<br />
Now, observe that, like any positive integer, <math>404</math> can be written as a sum of powers of two:<br />
<br />
<math>404 = 256 + 128 + 16 + 4</math><br />
<br />
We can now use this powers-of-two expansion to compute <math>\overline{13}^{404}</math>:<br />
<br />
<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><br />
<br />
So the tens and units digits of <math>13^{404}</math> are <math>6</math> and <math>1</math>, respectively.<br />
<br />
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>.<br />
<br />
This method can be further refined using [[Euler's Totient Theorem]].<br />
<br />
== Applications of Modular Arithmetic ==<br />
Modular arithmetic is an extremely flexible problem solving tool. The following topics are just a few applications and extensions of its use:<br />
* [[Divisibility rules]]<br />
* [[Linear congruence | Linear congruences]]<br />
<br />
<br />
<br />
== Resources ==<br />
* The AoPS [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?page_id=10 Introduction to Number Theory] by [[Mathew Crawford]].<br />
<br />
<br />
== See also ==<br />
* [[Intermediate modular arithmetic]]<br />
* [[Olympiad modular arithmetic]]</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic/Introduction&diff=5257Modular arithmetic/Introduction2006-06-29T05:25:06Z<p>Mathjoker: taking out the overlines</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]].<br />
<br />
<br />
<br />
== The Basic Idea ==<br />
Let's use a clock as an example, except let's replace the <math>\displaystyle 12</math> at the top of the clock with a <math>\displaystyle 0</math>. Starting at noon, the hour hand points in order to the following:<br />
<br />
<br />
<math>\displaystyle 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, \ldots </math><br />
<br />
<br />
This is the way in which we count in '''modulo 12'''. When we add <math>\displaystyle 1</math> to <math>\displaystyle 11</math>, we arrive back at <math>\displaystyle 0</math>. The same is true in any other [[modulus]] (modular arithmetic system). In modulo <math>\displaystyle 5</math>, we [[counting | count]]<br />
<br />
<br />
<math>\displaystyle 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, \ldots</math><br />
<br />
<br />
We can also count backwards in modulo 5. Any time we subtract 1 from 0, we get 4. So, the integers from <math>\displaystyle -12</math> to <math>\displaystyle 0</math>, when written in modulo 5, are<br />
<br />
<br />
<math>\displaystyle 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0,</math><br />
<br />
<br />
where <math>\displaystyle -12</math> is the same as <math>\displaystyle 3</math> in modulo 5. Because all integers can be expressed as <math>\displaystyle 0</math>, <math>\displaystyle 1</math>, <math>\displaystyle 2</math>, <math>\displaystyle 3</math>, or <math>\displaystyle 4</math> in modulo 5, we give these give integers their own name: the modulo 5 '''[[residue | residues]]'''. In general, for a natural number <math>\displaystyle n</math> that is greater than 1, the modulo <math>\displaystyle n</math> residues are the integers that are [[whole number | whole numbers]] less than <math>\displaystyle n</math>:<br />
<br />
<br />
<math>\displaystyle 0, 1, 2, \ldots, n-1. </math><br />
<br />
<br />
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!<br />
<br />
<br />
<br />
== Congruence ==<br />
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 <math>\displaystyle \equiv</math>:<br />
<br />
<br />
<center><math>\displaystyle 7 \equiv 2 \pmod{5}. </math></center><br />
<br />
<br />
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:<br />
<center><math>\displaystyle -12 \equiv -7 \equiv -2 \equiv 3 \equiv 8 \equiv 13 \equiv 18 \equiv 23 \pmod{5} </math></center><br />
In general, two integers <math>\displaystyle a</math> and <math>\displaystyle b</math> are congruent modulo <math>\displaystyle n</math> when <math>\displaystyle a - b</math> is a multiple of <math>\displaystyle n</math>. In other words, <math>\displaystyle a \equiv b \pmod{n}</math> when <math>\displaystyle \frac{a-b}{n}</math> is an integer. Otherwise, <math>\displaystyle a \not\equiv b \pmod{n}</math>, which means that <math>\displaystyle a</math> and <math>\displaystyle b</math> are '''not congruent''' modulo <math>\displaystyle n</math>.<br />
<br />
<br />
<br />
=== Examples ===<br />
* <math>\displaystyle 31 \equiv 1 \pmod{10}</math> because <math>\displaystyle 31 - 1 = 30</math> is a multiple of <math>\displaystyle 10</math><br />
<br />
<br />
* <math>\displaystyle 43 \equiv 22 \pmod{7}</math> because <math>\displaystyle \frac{43 - 22}{7} = \frac{21}{7} = 3</math>, which is an integer.<br />
<br />
<br />
* <math>\displaystyle 8 \not\equiv -8 \pmod{3}</math> because <math>\displaystyle 8 - (-8) = 16</math>, which is not a multiple of <math>\displaystyle 3</math>.<br />
<br />
<br />
* <math>\displaystyle 91 \not\equiv 18 \pmod{6}</math> because <math>\displaystyle \frac{91 - 18}{6} = \frac{73}{6}</math>, which is not an integer.<br />
<br />
<br />
<br />
=== Sample Problem ===<br />
Find the modulo <math>\displaystyle 4</math> residue of <math>\displaystyle 311</math>.<br />
==== Solution: ====<br />
Since <math>\displaystyle 311 \div 4 = 77</math> R <math>\displaystyle 3</math>, we know that <br />
<center><math>\displaystyle 311 \equiv 3 \pmod{4}</math></center><br />
and <math>\displaystyle 3</math> is the modulo <math>\displaystyle 4</math> residue of <math>\displaystyle 311</math>.<br />
<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
<br />
<br />
=== The Natural Appeal of Modular Arithmetic ===<br />
<br />
Observe that we use modular arithmetic even when solving some of the most basic, everyday problems. For example:<br />
<br />
''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?''<br />
<br />
We know that the hours of the day are numbered from <math>1</math> to <math>12</math>, with hours having the same number if and only if they are a multiple of <math>12</math> hours apart. So we can use subtraction mod <math>12</math> to answer this question.<br />
<br />
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<br />
<br />
<math>2 - 6 = -4 \equiv 8 \pmod{12}</math>.<br />
<br />
So Cody must quit studying at 8 AM.<br />
<br />
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 <math>\mathbb{Z}_n</math>: a "number circle." Just as we model addition and subtraction by moving along a number line, we can model addition and subtraction mod <math>n</math> 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.<br />
<br />
==== A Word of Caution ====<br />
<br />
Because of the way we define operations in <math>\mathbb{Z}_n</math>, it is important to check that these operations are well-defined. This is because each of the sets that make up <math>\mathbb{Z}_n</math> contains many different numbers, and therefore has many different names. For example, observe that in <math>\mathbb{Z}_7</math>, we have <math>\overline{1} = \overline{8}</math> and <math>\overline{2} = \overline{9}</math>. It is reasonable to expect that if we perform the addition <math>\overline{8} + \overline{9}</math>, we should get the same answer as if we compute <math>\overline{1} + \overline{2}</math>, since we are simply using different names for the same objects. Indeed, the first addition yields the sum <math>\overline{17} = \overline{3}</math>, which is the same as the result of the second addition.<br />
<br />
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]].<br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
We begin by writing down the first few powers of <math>7</math> mod <math>100</math>:<br />
<br />
<math>7, 49, 43, 1, 7, 49, 43, 1, \ldots</math><br />
<br />
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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
==== A General Algorithm ====<br />
<br />
In the example above, we were fortunate to find a power of <math>7</math> -- namely, <math>7^4</math> -- that is congruent to <math>1</math> mod <math>100</math>. What if we aren't this lucky? Suppose we want to solve the following problem:<br />
<br />
''What are the tens and units digits of <math>13^{404}</math>?''<br />
<br />
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<br />
<br />
<math>13, 69, 97, 61, 93, \ldots</math><br />
<br />
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?<br />
<br />
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>):<br />
<br />
<math>13^1 = 13</math><br />
<br />
<math>13^2 \equiv 69</math><br />
<br />
<math>13^4 \equiv 69^2 \equiv 61</math><br />
<br />
<math>13^8 \equiv 61^2 \equiv 21</math><br />
<br />
<math>13^{16} \equiv 21^2 \equiv 41</math><br />
<br />
<math>13^{32} \equiv 41^2 \equiv 81</math><br />
<br />
<math>13^{64} \equiv 81^2 \equiv 61</math><br />
<br />
<math>13^{128} \equiv 61^2 \equiv 21</math><br />
<br />
<math>13^{256} \equiv 21^2 \equiv 41</math><br />
<br />
(Observe that this process yields a pattern of its own, if we carry it out far enough!)<br />
<br />
Now, observe that, like any positive integer, <math>404</math> can be written as a sum of powers of two:<br />
<br />
<math>404 = 256 + 128 + 16 + 4</math><br />
<br />
We can now use this powers-of-two expansion to compute <math>\overline{13}^{404}</math>:<br />
<br />
<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><br />
<br />
So the tens and units digits of <math>13^{404}</math> are <math>6</math> and <math>1</math>, respectively.<br />
<br />
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>.<br />
<br />
This method can be further refined using [[Euler's Totient Theorem]].<br />
<br />
== Applications of Modular Arithmetic ==<br />
Modular arithmetic is an extremely flexible problem solving tool. The following topics are just a few applications and extensions of its use:<br />
* [[Divisibility rules]]<br />
* [[Linear congruence | Linear congruences]]<br />
<br />
<br />
<br />
== Resources ==<br />
* The AoPS [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?page_id=10 Introduction to Number Theory] by [[Mathew Crawford]].<br />
<br />
<br />
== See also ==<br />
* [[Intermediate modular arithmetic]]<br />
* [[Olympiad modular arithmetic]]</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic/Introduction&diff=5256Modular arithmetic/Introduction2006-06-29T05:13:01Z<p>Mathjoker: /* The Natural Appeal of Modular Arithmetic */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]].<br />
<br />
<br />
<br />
== The Basic Idea ==<br />
Let's use a clock as an example, except let's replace the <math>\displaystyle 12</math> at the top of the clock with a <math>\displaystyle 0</math>. Starting at noon, the hour hand points in order to the following:<br />
<br />
<br />
<math>\displaystyle 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, \ldots </math><br />
<br />
<br />
This is the way in which we count in '''modulo 12'''. When we add <math>\displaystyle 1</math> to <math>\displaystyle 11</math>, we arrive back at <math>\displaystyle 0</math>. The same is true in any other [[modulus]] (modular arithmetic system). In modulo <math>\displaystyle 5</math>, we [[counting | count]]<br />
<br />
<br />
<math>\displaystyle 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, \ldots</math><br />
<br />
<br />
We can also count backwards in modulo 5. Any time we subtract 1 from 0, we get 4. So, the integers from <math>\displaystyle -12</math> to <math>\displaystyle 0</math>, when written in modulo 5, are<br />
<br />
<br />
<math>\displaystyle 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0,</math><br />
<br />
<br />
where <math>\displaystyle -12</math> is the same as <math>\displaystyle 3</math> in modulo 5. Because all integers can be expressed as <math>\displaystyle 0</math>, <math>\displaystyle 1</math>, <math>\displaystyle 2</math>, <math>\displaystyle 3</math>, or <math>\displaystyle 4</math> in modulo 5, we give these give integers their own name: the modulo 5 '''[[residue | residues]]'''. In general, for a natural number <math>\displaystyle n</math> that is greater than 1, the modulo <math>\displaystyle n</math> residues are the integers that are [[whole number | whole numbers]] less than <math>\displaystyle n</math>:<br />
<br />
<br />
<math>\displaystyle 0, 1, 2, \ldots, n-1. </math><br />
<br />
<br />
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!<br />
<br />
<br />
<br />
== Congruence ==<br />
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 <math>\displaystyle \equiv</math>:<br />
<br />
<br />
<center><math>\displaystyle 7 \equiv 2 \pmod{5}. </math></center><br />
<br />
<br />
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:<br />
<center><math>\displaystyle -12 \equiv -7 \equiv -2 \equiv 3 \equiv 8 \equiv 13 \equiv 18 \equiv 23 \pmod{5} </math></center><br />
In general, two integers <math>\displaystyle a</math> and <math>\displaystyle b</math> are congruent modulo <math>\displaystyle n</math> when <math>\displaystyle a - b</math> is a multiple of <math>\displaystyle n</math>. In other words, <math>\displaystyle a \equiv b \pmod{n}</math> when <math>\displaystyle \frac{a-b}{n}</math> is an integer. Otherwise, <math>\displaystyle a \not\equiv b \pmod{n}</math>, which means that <math>\displaystyle a</math> and <math>\displaystyle b</math> are '''not congruent''' modulo <math>\displaystyle n</math>.<br />
<br />
<br />
<br />
=== Examples ===<br />
* <math>\displaystyle 31 \equiv 1 \pmod{10}</math> because <math>\displaystyle 31 - 1 = 30</math> is a multiple of <math>\displaystyle 10</math><br />
<br />
<br />
* <math>\displaystyle 43 \equiv 22 \pmod{7}</math> because <math>\displaystyle \frac{43 - 22}{7} = \frac{21}{7} = 3</math>, which is an integer.<br />
<br />
<br />
* <math>\displaystyle 8 \not\equiv -8 \pmod{3}</math> because <math>\displaystyle 8 - (-8) = 16</math>, which is not a multiple of <math>\displaystyle 3</math>.<br />
<br />
<br />
* <math>\displaystyle 91 \not\equiv 18 \pmod{6}</math> because <math>\displaystyle \frac{91 - 18}{6} = \frac{73}{6}</math>, which is not an integer.<br />
<br />
<br />
<br />
=== Sample Problem ===<br />
Find the modulo <math>\displaystyle 4</math> residue of <math>\displaystyle 311</math>.<br />
==== Solution: ====<br />
Since <math>\displaystyle 311 \div 4 = 77</math> R <math>\displaystyle 3</math>, we know that <br />
<center><math>\displaystyle 311 \equiv 3 \pmod{4}</math></center><br />
and <math>\displaystyle 3</math> is the modulo <math>\displaystyle 4</math> residue of <math>\displaystyle 311</math>.<br />
<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
<br />
<br />
=== The Natural Appeal of Modular Arithmetic ===<br />
<br />
Observe that we use modular arithmetic even when solving some of the most basic, everyday problems. For example:<br />
<br />
''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?''<br />
<br />
We know that the hours of the day are numbered from <math>1</math> to <math>12</math>, with hours having the same number if and only if they are a multiple of <math>12</math> hours apart. So we can use subtraction mod <math>12</math> to answer this question.<br />
<br />
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<br />
<br />
<math>2 - 6 = -4 \equiv 8 \pmod{12}</math>.<br />
<br />
So Cody must quit studying at 8 AM.<br />
<br />
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 <math>\mathbb{Z}_n</math>: a "number circle." Just as we model addition and subtraction by moving along a number line, we can model addition and subtraction mod <math>n</math> 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.<br />
<br />
==== A Word of Caution ====<br />
<br />
Because of the way we define operations in <math>\mathbb{Z}_n</math>, it is important to check that these operations are well-defined. This is because each of the sets that make up <math>\mathbb{Z}_n</math> contains many different numbers, and therefore has many different names. For example, observe that in <math>\mathbb{Z}_7</math>, we have <math>\overline{1} = \overline{8}</math> and <math>\overline{2} = \overline{9}</math>. It is reasonable to expect that if we perform the addition <math>\overline{8} + \overline{9}</math>, we should get the same answer as if we compute <math>\overline{1} + \overline{2}</math>, since we are simply using different names for the same objects. Indeed, the first addition yields the sum <math>\overline{17} = \overline{3}</math>, which is the same as the result of the second addition.<br />
<br />
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]].<br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
We begin by writing down the first few powers of <math>\overline{7}</math>:<br />
<br />
<math>\overline{7}, \overline{49}, \overline{43}, \overline{1}, \overline{7}, \overline{49}, \overline{43}, \overline{1}, \ldots</math><br />
<br />
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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
==== A General Algorithm ====<br />
<br />
In the example above, we were fortunate to find a power of <math>7</math> -- namely, <math>7^4</math> -- that is congruent to <math>1</math> mod <math>100</math>. What if we aren't this lucky? Suppose we want to solve the following problem:<br />
<br />
''What are the tens and units digits of <math>13^{404}</math>?''<br />
<br />
Again, we will solve this problem by computing <math>\overline{13}^{404}</math> modulo <math>100</math>. The first few powers of <math>\overline{13}</math> are<br />
<br />
<math>\overline{13}, \overline{69}, \overline{97}, \overline{61}, \overline{93}, \ldots</math><br />
<br />
This time, no pattern jumps out at us. Is there a way we can find the <math>404^{th}</math> power of <math>\overline{13}</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?<br />
<br />
Suppose we condense the list we started above; and instead of writing down all powers of <math>\overline{13}</math>, we write only the powers <math>\overline{13}^k</math>, where <math>k</math> is a power of <math>2</math>. We have<br />
<br />
<math>\overline{13}^1 = \overline{13}</math><br />
<br />
<math>\overline{13}^2 = \overline{69}</math><br />
<br />
<math>\overline{13}^4 = \overline{69}^2 = \overline{61}</math><br />
<br />
<math>\overline{13}^8 = \overline{61}^2 = \overline{21}</math><br />
<br />
<math>\overline{13}^{16} = \overline{21}^2 = \overline{41}</math><br />
<br />
<math>\overline{13}^{32} = \overline{41}^2 = \overline{81}</math><br />
<br />
<math>\overline{13}^{64} = \overline{81}^2 = \overline{61}</math><br />
<br />
<math>\overline{13}^{128} = \overline{61}^2 = \overline{21}</math><br />
<br />
<math>\overline{13}^{256} = \overline{21}^2 = \overline{41}</math><br />
<br />
(Observe that this process yields a pattern of its own, if we carry it out far enough!)<br />
<br />
Now, observe that, like any positive integer, <math>404</math> can be written as a sum of powers of two:<br />
<br />
<math>404 = 256 + 128 + 16 + 4</math><br />
<br />
We can now use this powers-of-two expansion to compute <math>\overline{13}^{404}</math>:<br />
<br />
<math>\overline{13}^{404} = \overline{13}^{256} \cdot \overline{13}^{128} \cdot \overline{13}^{16} \cdot \overline{13}^4 = \overline{41} \cdot \overline{21} \cdot \overline{41} \cdot \overline{61} = \overline{61}.</math><br />
<br />
So the tens and units digits of <math>13^{404}</math> are <math>6</math> and <math>1</math>, respectively.<br />
<br />
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>\overline{M}^k</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>\overline{M}</math> according to the binary representation of <math>e</math>.<br />
<br />
This method can be further refined using [[Euler's Totient Theorem]].<br />
<br />
<br />
<br />
== Applications of Modular Arithmetic ==<br />
Modular arithmetic is an extremely flexible problem solving tool. The following topics are just a few applications and extensions of its use:<br />
* [[Divisibility rules]]<br />
* [[Linear congruence | Linear congruences]]<br />
<br />
<br />
<br />
== Resources ==<br />
* The AoPS [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?page_id=10 Introduction to Number Theory] by [[Mathew Crawford]].<br />
<br />
<br />
== See also ==<br />
* [[Intermediate modular arithmetic]]<br />
* [[Olympiad modular arithmetic]]</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=5086Modular arithmetic2006-06-28T04:20:26Z<p>Mathjoker: algebraic properties of Z mod n</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
==== Examples ====<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== The Integers Modulo n ===<br />
<br />
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements. For example, if <math>n = 3</math>, then the integers are divided into the following sets:<br />
<br />
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math><br />
<br />
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math><br />
<br />
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math><br />
<br />
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).<br />
<br />
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it. For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>. The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third. The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.<br />
<br />
Instead of thinking of the objects <math>\overline{0}</math>, <math>\overline{1}</math>, and <math>\overline{2}</math> as sets, we can treat them as algebraic objects -- like numbers -- with their own operations of addition and multiplication. Together, these objects form '''the integers modulo <math>3</math>,''' or <math>\mathbb{Z}_3</math>. More generally, if <math>n</math> is a positive integer, then we can define<br />
<br />
<math>\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}</math>,<br />
<br />
where for each <math>k</math>, <math>\overline{k}</math> is defined by<br />
<br />
<math>\overline{k} = \{ m \in \mathbb{Z} \mbox{ such that } m \equiv k \pmod{n} \}.</math><br />
<br />
=== Addition, Subtraction, and Multiplication Mod n ===<br />
<br />
We define addition, subtraction, and multiplication in <math>\mathbb{Z}_n</math> according to the following rules:<br />
<br />
<math>\overline{a} + \overline{b} = \overline{a+b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Addition)<br />
<br />
<math>\overline{a} - \overline{b} = \overline{a-b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Subtraction)<br />
<br />
<math>\overline{a} \cdot \overline{b} = \overline{ab}</math> for all <math>a, b \in \mathbb{Z}</math>. (Multiplication)<br />
<br />
So for example, if <math>n = 7</math>, then we have<br />
<br />
<math>\overline{3} + \overline{2} = \overline{3+2} = \overline{5}</math><br />
<br />
<math>\overline{4} + \overline{4} = \overline{4+4} = \overline{8} = \overline{1}</math><br />
<br />
<math>\overline{4} \cdot \overline{3} = \overline{4 \cdot 3} = \overline{12} = \overline{5}</math><br />
<br />
<math>\overline{6} \cdot \overline{6} = \overline{6 \cdot 6} = \overline{36} = \overline{1}</math><br />
<br />
Notice that, in each case, we reduce to an answer of the form <math>\overline{k}</math>, where <math>0 \leq k < 7</math>. We do this for two reasons: to keep possible future calculations as manageable as possible, and to emphasize the point that each expression takes one of only seven (or in general, <math>n</math>) possible values. (Some people find it useful to reduce an answer such as <math>\overline{5}</math> to <math>\overline{-2}</math>, which is negative but has a smaller absolute value.)<br />
<br />
==== The Natural Appeal of Modular Arithmetic ====<br />
<br />
Observe that we use modular arithmetic even when solving some of the most basic, everyday problems. For example:<br />
<br />
''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?''<br />
<br />
We know that the hours of the day are numbered from <math>1</math> to <math>12</math>, with hours having the same number if and only if they are a multiple of <math>12</math> hours apart. So we can use subtraction mod <math>12</math> to answer this question.<br />
<br />
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<br />
<br />
<math>\overline{2} - \overline{6} = \overline{-4} = \overline{8}.</math><br />
<br />
So Cody must quit studying at 8 AM.<br />
<br />
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 <math>\mathbb{Z}_n</math>: a "number circle." Just as we model addition and subtraction by moving along a number line, we can model addition and subtraction mod <math>n</math> 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.<br />
<br />
==== A Word of Caution ====<br />
<br />
Because of the way we define operations in <math>\mathbb{Z}_n</math>, it is important to check that these operations are well-defined. This is because each of the sets that make up <math>\mathbb{Z}_n</math> contains many different numbers, and therefore has many different names. For example, observe that in <math>\mathbb{Z}_7</math>, we have <math>\overline{1} = \overline{8}</math> and <math>\overline{2} = \overline{9}</math>. It is reasonable to expect that if we perform the addition <math>\overline{8} + \overline{9}</math>, we should get the same answer as if we compute <math>\overline{1} + \overline{2}</math>, since we are simply using different names for the same objects. Indeed, the first addition yields the sum <math>\overline{17} = \overline{3}</math>, which is the same as the result of the second addition.<br />
<br />
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]].<br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
We begin by writing down the first few powers of <math>\overline{7}</math>:<br />
<br />
<math>\overline{7}, \overline{49}, \overline{43}, \overline{1}, \overline{7}, \overline{49}, \overline{43}, \overline{1}, \ldots</math><br />
<br />
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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
==== A General Algorithm ====<br />
<br />
In the example above, we were fortunate to find a power of <math>7</math> -- namely, <math>7^4</math> -- that is congruent to <math>1</math> mod <math>100</math>. What if we aren't this lucky? Suppose we want to solve the following problem:<br />
<br />
''What are the tens and units digits of <math>13^{404}</math>?''<br />
<br />
Again, we will solve this problem by computing <math>\overline{13}^{404}</math> modulo <math>100</math>. The first few powers of <math>\overline{13}</math> are<br />
<br />
<math>\overline{13}, \overline{69}, \overline{97}, \overline{61}, \overline{93}, \ldots</math><br />
<br />
This time, no pattern jumps out at us. Is there a way we can find the <math>404^{th}</math> power of <math>\overline{13}</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?<br />
<br />
Suppose we condense the list we started above; and instead of writing down all powers of <math>\overline{13}</math>, we write only the powers <math>\overline{13}^k</math>, where <math>k</math> is a power of <math>2</math>. We have<br />
<br />
<math>\overline{13}^1 = \overline{13}</math><br />
<br />
<math>\overline{13}^2 = \overline{69}</math><br />
<br />
<math>\overline{13}^4 = \overline{69}^2 = \overline{61}</math><br />
<br />
<math>\overline{13}^8 = \overline{61}^2 = \overline{21}</math><br />
<br />
<math>\overline{13}^{16} = \overline{21}^2 = \overline{41}</math><br />
<br />
<math>\overline{13}^{32} = \overline{41}^2 = \overline{81}</math><br />
<br />
<math>\overline{13}^{64} = \overline{81}^2 = \overline{61}</math><br />
<br />
<math>\overline{13}^{128} = \overline{61}^2 = \overline{21}</math><br />
<br />
<math>\overline{13}^{256} = \overline{21}^2 = \overline{41}</math><br />
<br />
(Observe that this process yields a pattern of its own, if we carry it out far enough!)<br />
<br />
Now, observe that, like any positive integer, <math>404</math> can be written as a sum of powers of two:<br />
<br />
<math>404 = 256 + 128 + 16 + 4</math><br />
<br />
We can now use this powers-of-two expansion to compute <math>\overline{13}^{404}</math>:<br />
<br />
<math>\overline{13}^{404} = \overline{13}^{256} \cdot \overline{13}^{128} \cdot \overline{13}^{16} \cdot \overline{13}^4 = \overline{41} \cdot \overline{21} \cdot \overline{41} \cdot \overline{61} = \overline{61}.</math><br />
<br />
So the tens and units digits of <math>13^{404}</math> are <math>6</math> and <math>1</math>, respectively.<br />
<br />
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>\overline{M}^k</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>\overline{M}</math> according to the binary representation of <math>e</math>.<br />
<br />
This method can be further refined using [[Euler's Totient Theorem]].<br />
<br />
=== Algebraic Properties of the Integers Mod n ===<br />
<br />
The integers modulo <math>n</math> form an algebraic structure called a [[ring]] -- a structure in which we can add, subtract, and multiply elements.<br />
<br />
Anyone who has taken a high school algebra class is familiar with several examples of rings, including the ring of integers, the ring of rational numbers, and the ring of real numbers. The ring <math>\mathbb{Z}_n</math> has some algebraic features that make it quite different from the more familiar rings listed above.<br />
<br />
First of all, notice that if we choose a nonzero element <math>\overline{a}</math> of <math>\mathbb{Z}_n</math>, and add <math>n</math> copies of this element, we get<br />
<br />
<math>\overline{a} + \overline{a} + \cdots + \overline{a} = n \cdot \overline{a} = \overline{na} = \overline{0}</math>,<br />
<br />
since <math>na</math> is a multiple of <math>n</math>. So it is possible to add several copies of a nonzero element of <math>\mathbb{Z}_n</math> and get zero. This phenomenon, which is called '''torsion''', does not occur in the reals, the rationals, or the integers.<br />
<br />
Another curious feature of <math>\mathbb{Z}_n</math> is that a polynomial over <math>\mathbb{Z}_n</math> can have a number of roots greater than its degree. Consider, for example, the polynomial congruence<br />
<br />
<math>x^2 - 2x - 15 \equiv 0 \pmod{21}</math>.<br />
<br />
We might be tempted to solve this congruence by factoring the expression on the left:<br />
<br />
<math>(x - 5)(x + 3) \equiv 0 \pmod{21}</math>.<br />
<br />
Indeed, this factorization yields two solutions to the congruence: <math>x \equiv 5 \pmod{21}</math>, and <math>x \equiv -3 \equiv 18 \pmod{21}</math>. (Note that two values of <math>x</math> that are congruent modulo <math>21</math> are considered the same solution.)<br />
<br />
However, since <math>15 \equiv 99 \pmod{21}</math>, the original congruence is equivalent to<br />
<br />
<math>x^2 - 2x - 99 \equiv 0 \pmod{21}</math>.<br />
<br />
This time, factoring the expression on the left yields<br />
<br />
<math>(x - 11)(x + 9) \equiv 0 \pmod{21}</math>.<br />
<br />
And we find that there are two more solutions! The values <math>x \equiv 11 \pmod{21}</math> and <math>x \equiv -9 \equiv 12 \pmod{21}</math> both solve the congruence. So our congruence has at least four solutions -- two more than we might expect based on the degree of the polynomial.<br />
<br />
Why do the "rules" of algebra that work so well for the real numbers seem to fail in <math>\mathbb{Z}_{21}</math>? To understand this, let's take a closer look at the congruence<br />
<br />
<math>(x - 5)(x + 3) \equiv 0 \pmod{21}</math>.<br />
<br />
If we were solving this as an equation over the reals, we would immediately conclude that either <math>x - 5</math> must be zero, or <math>x + 3</math> must be zero in order for the product to equal zero. However, this is not the case in <math>\mathbb{Z}_{21}</math>! It is possible to multiply two nonzero elements of <math>\mathbb{Z}_{21}</math> and get zero. For example, we have<br />
<br />
<math>\overline{3} \cdot \overline{7} = \overline{0}</math><br />
<br />
<math>\overline{9} \cdot \overline{7} = \overline{0}</math><br />
<br />
<math>\overline{6} \cdot \overline{14} = \overline{0}</math><br />
<br />
But wait! Suppose we take a close look at this last product, and we set <math>x - 5 \equiv 6 \pmod{21}</math> and <math>x + 3 \equiv 14 \pmod{21}</math>. Then we have <math>x \equiv 11 \pmod{21}</math> -- another of the solutions of our congruence! (One can check that the other two factorizations don't lead to any valid solutions; however, there are many other factorizations of zero that need to be checked.)<br />
<br />
In the ring of real numbers, it is a well-known fact that if <math>ab = 0</math>, then <math>a = 0</math> or <math>b = 0</math>. For this reason, we call the ring of real numbers a '''domain'''. However, a similar fact does ''not'' apply in general in <math>\mathbb{Z}_n</math>; therefore, <math>\mathbb{Z}_n</math> is not in general a domain.<br />
<br />
== Theorems and Applications ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).<br />
<br />
<br />
<br />
== Resources ==<br />
* The AoPS [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?page_id=10 Introduction to Number Theory] by [[Mathew Crawford]].</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=5002Modular arithmetic2006-06-27T19:02:52Z<p>Mathjoker: /* Computation of Powers Mod n */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
==== Examples ====<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== The Integers Modulo n ===<br />
<br />
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements. For example, if <math>n = 3</math>, then the integers are divided into the following sets:<br />
<br />
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math><br />
<br />
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math><br />
<br />
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math><br />
<br />
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).<br />
<br />
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it. For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>. The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third. The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.<br />
<br />
Instead of thinking of the objects <math>\overline{0}</math>, <math>\overline{1}</math>, and <math>\overline{2}</math> as sets, we can treat them as algebraic objects -- like numbers -- with their own operations of addition and multiplication. Together, these objects form '''the integers modulo <math>3</math>,''' or <math>\mathbb{Z}_3</math>. More generally, if <math>n</math> is a positive integer, then we can define<br />
<br />
<math>\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}</math>,<br />
<br />
where for each <math>k</math>, <math>\overline{k}</math> is defined by<br />
<br />
<math>\overline{k} = \{ m \in \mathbb{Z} \mbox{ such that } m \equiv k \pmod{n} \}.</math><br />
<br />
=== Addition, Subtraction, and Multiplication Mod n ===<br />
<br />
We define addition, subtraction, and multiplication in <math>\mathbb{Z}_n</math> according to the following rules:<br />
<br />
<math>\overline{a} + \overline{b} = \overline{a+b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Addition)<br />
<br />
<math>\overline{a} - \overline{b} = \overline{a-b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Subtraction)<br />
<br />
<math>\overline{a} \cdot \overline{b} = \overline{ab}</math> for all <math>a, b \in \mathbb{Z}</math>. (Multiplication)<br />
<br />
So for example, if <math>n = 7</math>, then we have<br />
<br />
<math>\overline{3} + \overline{2} = \overline{3+2} = \overline{5}</math><br />
<br />
<math>\overline{4} + \overline{4} = \overline{4+4} = \overline{8} = \overline{1}</math><br />
<br />
<math>\overline{4} \cdot \overline{3} = \overline{4 \cdot 3} = \overline{12} = \overline{5}</math><br />
<br />
<math>\overline{6} \cdot \overline{6} = \overline{6 \cdot 6} = \overline{36} = \overline{1}</math><br />
<br />
Notice that, in each case, we reduce to an answer of the form <math>\overline{k}</math>, where <math>0 \leq k < 7</math>. We do this for two reasons: to keep possible future calculations as manageable as possible, and to emphasize the point that each expression takes one of only seven (or in general, <math>n</math>) possible values. (Some people find it useful to reduce an answer such as <math>\overline{5}</math> to <math>\overline{-2}</math>, which is negative but has a smaller absolute value.)<br />
<br />
==== The Natural Appeal of Modular Arithmetic ====<br />
<br />
Observe that we use modular arithmetic even when solving some of the most basic, everyday problems. For example:<br />
<br />
''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?''<br />
<br />
We know that the hours of the day are numbered from <math>1</math> to <math>12</math>, with hours having the same number if and only if they are a multiple of <math>12</math> hours apart. So we can use subtraction mod <math>12</math> to answer this question.<br />
<br />
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<br />
<br />
<math>\overline{2} - \overline{6} = \overline{-4} = \overline{8}.</math><br />
<br />
So Cody must quit studying at 8 AM.<br />
<br />
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 <math>\mathbb{Z}_n</math>: a "number circle." Just as we model addition and subtraction by moving along a number line, we can model addition and subtraction mod <math>n</math> 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.<br />
<br />
==== A Word of Caution ====<br />
<br />
Because of the way we define operations in <math>\mathbb{Z}_n</math>, it is important to check that these operations are well-defined. This is because each of the sets that make up <math>\mathbb{Z}_n</math> contains many different numbers, and therefore has many different names. For example, observe that in <math>\mathbb{Z}_7</math>, we have <math>\overline{1} = \overline{8}</math> and <math>\overline{2} = \overline{9}</math>. It is reasonable to expect that if we perform the addition <math>\overline{8} + \overline{9}</math>, we should get the same answer as if we compute <math>\overline{1} + \overline{2}</math>, since we are simply using different names for the same objects. Indeed, the first addition yields the sum <math>\overline{17} = \overline{3}</math>, which is the same as the result of the second addition.<br />
<br />
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]].<br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
We begin by writing down the first few powers of <math>\overline{7}</math>:<br />
<br />
<math>\overline{7}, \overline{49}, \overline{43}, \overline{1}, \overline{7}, \overline{49}, \overline{43}, \overline{1}, \ldots</math><br />
<br />
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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
==== A General Algorithm ====<br />
<br />
In the example above, we were fortunate to find a power of <math>7</math> -- namely, <math>7^4</math> -- that is congruent to <math>1</math> mod <math>100</math>. What if we aren't this lucky? Suppose we want to solve the following problem:<br />
<br />
''What are the tens and units digits of <math>13^{404}</math>?''<br />
<br />
Again, we will solve this problem by computing <math>\overline{13}^{404}</math> modulo <math>100</math>. The first few powers of <math>\overline{13}</math> are<br />
<br />
<math>\overline{13}, \overline{69}, \overline{97}, \overline{61}, \overline{93}, \ldots</math><br />
<br />
This time, no pattern jumps out at us. Is there a way we can find the <math>404^{th}</math> power of <math>\overline{13}</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?<br />
<br />
Suppose we condense the list we started above; and instead of writing down all powers of <math>\overline{13}</math>, we write only the powers <math>\overline{13}^k</math>, where <math>k</math> is a power of <math>2</math>. We have<br />
<br />
<math>\overline{13}^1 = \overline{13}</math><br />
<br />
<math>\overline{13}^2 = \overline{69}</math><br />
<br />
<math>\overline{13}^4 = \overline{69}^2 = \overline{61}</math><br />
<br />
<math>\overline{13}^8 = \overline{61}^2 = \overline{21}</math><br />
<br />
<math>\overline{13}^{16} = \overline{21}^2 = \overline{41}</math><br />
<br />
<math>\overline{13}^{32} = \overline{41}^2 = \overline{81}</math><br />
<br />
<math>\overline{13}^{64} = \overline{81}^2 = \overline{61}</math><br />
<br />
<math>\overline{13}^{128} = \overline{61}^2 = \overline{21}</math><br />
<br />
<math>\overline{13}^{256} = \overline{21}^2 = \overline{41}</math><br />
<br />
(Observe that this process yields a pattern of its own, if we carry it out far enough!)<br />
<br />
Now, observe that, like any positive integer, <math>404</math> can be written as a sum of powers of two:<br />
<br />
<math>404 = 256 + 128 + 16 + 4</math><br />
<br />
We can now use this powers-of-two expansion to compute <math>\overline{13}^{404}</math>:<br />
<br />
<math>\overline{13}^{404} = \overline{13}^{256} \cdot \overline{13}^{128} \cdot \overline{13}^{16} \cdot \overline{13}^4 = \overline{41} \cdot \overline{21} \cdot \overline{41} \cdot \overline{61} = \overline{61}.</math><br />
<br />
So the tens and units digits of <math>13^{404}</math> are <math>6</math> and <math>1</math>, respectively.<br />
<br />
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>\overline{M}^k</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>\overline{M}</math> according to the binary representation of <math>e</math>.<br />
<br />
This method can be further refined using [[Euler's Totient Theorem]].<br />
<br />
== Intermediate ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).<br />
<br />
<br />
<br />
== Resources ==<br />
* The AoPS [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?page_id=10 Introduction to Number Theory] by [[Mathew Crawford]].</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4908Modular arithmetic2006-06-27T07:52:16Z<p>Mathjoker: /* Arithmetic Modulo n */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
==== Examples ====<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== The Integers Modulo n ===<br />
<br />
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements. For example, if <math>n = 3</math>, then the integers are divided into the following sets:<br />
<br />
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math><br />
<br />
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math><br />
<br />
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math><br />
<br />
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).<br />
<br />
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it. For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>. The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third. The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.<br />
<br />
Instead of thinking of the objects <math>\overline{0}</math>, <math>\overline{1}</math>, and <math>\overline{2}</math> as sets, we can treat them as algebraic objects -- like numbers -- with their own operations of addition and multiplication. Together, these objects form '''the integers modulo <math>3</math>,''' or <math>\mathbb{Z}_3</math>. More generally, if <math>n</math> is a positive integer, then we can define<br />
<br />
<math>\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}</math>,<br />
<br />
where for each <math>k</math>, <math>\overline{k}</math> is defined by<br />
<br />
<math>\overline{k} = \{ m \in \mathbb{Z} \mbox{ such that } m \equiv k \pmod{n} \}.</math><br />
<br />
=== Addition, Subtraction, and Multiplication Mod n ===<br />
<br />
We define addition, subtraction, and multiplication in <math>\mathbb{Z}_n</math> according to the following rules:<br />
<br />
<math>\overline{a} + \overline{b} = \overline{a+b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Addition)<br />
<br />
<math>\overline{a} - \overline{b} = \overline{a-b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Subtraction)<br />
<br />
<math>\overline{a} \cdot \overline{b} = \overline{ab}</math> for all <math>a, b \in \mathbb{Z}</math>. (Multiplication)<br />
<br />
So for example, if <math>n = 7</math>, then we have<br />
<br />
<math>\overline{3} + \overline{2} = \overline{3+2} = \overline{5}</math><br />
<br />
<math>\overline{4} + \overline{4} = \overline{4+4} = \overline{8} = \overline{1}</math><br />
<br />
<math>\overline{4} \cdot \overline{3} = \overline{4 \cdot 3} = \overline{12} = \overline{5}</math><br />
<br />
<math>\overline{6} \cdot \overline{6} = \overline{6 \cdot 6} = \overline{36} = \overline{1}</math><br />
<br />
Notice that, in each case, we reduce to an answer of the form <math>\overline{k}</math>, where <math>0 \leq k < 7</math>. We do this for two reasons: to keep possible future calculations as manageable as possible, and to emphasize the point that each expression takes one of only seven (or in general, <math>n</math>) possible values. (Some people find it useful to reduce an answer such as <math>\overline{5}</math> to <math>\overline{-2}</math>, which is negative but has a smaller absolute value.)<br />
<br />
==== The Natural Appeal of Modular Arithmetic ====<br />
<br />
Observe that we use modular arithmetic even when solving some of the most basic, everyday problems. For example:<br />
<br />
''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?''<br />
<br />
We know that the hours of the day are numbered from <math>1</math> to <math>12</math>, with hours having the same number if and only if they are a multiple of <math>12</math> hours apart. So we can use subtraction mod <math>12</math> to answer this question.<br />
<br />
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<br />
<br />
<math>\overline{2} - \overline{6} = \overline{-4} = \overline{8}.</math><br />
<br />
So Cody must quit studying at 8 AM.<br />
<br />
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 <math>\mathbb{Z}_n</math>: a "number circle." Just as we model addition and subtraction by moving along a number line, we can model addition and subtraction mod <math>n</math> 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.<br />
<br />
==== A Word of Caution ====<br />
<br />
Because of the way we define operations in <math>\mathbb{Z}_n</math>, it is important to check that these operations are well-defined. This is because each of the sets that make up <math>\mathbb{Z}_n</math> contains many different numbers, and therefore has many different names. For example, observe that in <math>\mathbb{Z}_7</math>, we have <math>\overline{1} = \overline{8}</math> and <math>\overline{2} = \overline{9}</math>. It is reasonable to expect that if we perform the addition <math>\overline{8} + \overline{9}</math>, we should get the same answer as if we compute <math>\overline{1} + \overline{2}</math>, since we are simply using different names for the same objects. Indeed, the first addition yields the sum <math>\overline{17} = \overline{3}</math>, which is the same as the result of the second addition.<br />
<br />
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]].<br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
== Intermediate ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4907Modular arithmetic2006-06-27T07:51:49Z<p>Mathjoker: /* Addition, Subtraction, and Multiplication Mod n */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== The Integers Modulo n ===<br />
<br />
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements. For example, if <math>n = 3</math>, then the integers are divided into the following sets:<br />
<br />
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math><br />
<br />
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math><br />
<br />
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math><br />
<br />
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).<br />
<br />
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it. For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>. The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third. The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.<br />
<br />
Instead of thinking of the objects <math>\overline{0}</math>, <math>\overline{1}</math>, and <math>\overline{2}</math> as sets, we can treat them as algebraic objects -- like numbers -- with their own operations of addition and multiplication. Together, these objects form '''the integers modulo <math>3</math>,''' or <math>\mathbb{Z}_3</math>. More generally, if <math>n</math> is a positive integer, then we can define<br />
<br />
<math>\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}</math>,<br />
<br />
where for each <math>k</math>, <math>\overline{k}</math> is defined by<br />
<br />
<math>\overline{k} = \{ m \in \mathbb{Z} \mbox{ such that } m \equiv k \pmod{n} \}.</math><br />
<br />
=== Addition, Subtraction, and Multiplication Mod n ===<br />
<br />
We define addition, subtraction, and multiplication in <math>\mathbb{Z}_n</math> according to the following rules:<br />
<br />
<math>\overline{a} + \overline{b} = \overline{a+b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Addition)<br />
<br />
<math>\overline{a} - \overline{b} = \overline{a-b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Subtraction)<br />
<br />
<math>\overline{a} \cdot \overline{b} = \overline{ab}</math> for all <math>a, b \in \mathbb{Z}</math>. (Multiplication)<br />
<br />
So for example, if <math>n = 7</math>, then we have<br />
<br />
<math>\overline{3} + \overline{2} = \overline{3+2} = \overline{5}</math><br />
<br />
<math>\overline{4} + \overline{4} = \overline{4+4} = \overline{8} = \overline{1}</math><br />
<br />
<math>\overline{4} \cdot \overline{3} = \overline{4 \cdot 3} = \overline{12} = \overline{5}</math><br />
<br />
<math>\overline{6} \cdot \overline{6} = \overline{6 \cdot 6} = \overline{36} = \overline{1}</math><br />
<br />
Notice that, in each case, we reduce to an answer of the form <math>\overline{k}</math>, where <math>0 \leq k < 7</math>. We do this for two reasons: to keep possible future calculations as manageable as possible, and to emphasize the point that each expression takes one of only seven (or in general, <math>n</math>) possible values. (Some people find it useful to reduce an answer such as <math>\overline{5}</math> to <math>\overline{-2}</math>, which is negative but has a smaller absolute value.)<br />
<br />
==== The Natural Appeal of Modular Arithmetic ====<br />
<br />
Observe that we use modular arithmetic even when solving some of the most basic, everyday problems. For example:<br />
<br />
''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?''<br />
<br />
We know that the hours of the day are numbered from <math>1</math> to <math>12</math>, with hours having the same number if and only if they are a multiple of <math>12</math> hours apart. So we can use subtraction mod <math>12</math> to answer this question.<br />
<br />
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<br />
<br />
<math>\overline{2} - \overline{6} = \overline{-4} = \overline{8}.</math><br />
<br />
So Cody must quit studying at 8 AM.<br />
<br />
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 <math>\mathbb{Z}_n</math>: a "number circle." Just as we model addition and subtraction by moving along a number line, we can model addition and subtraction mod <math>n</math> 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.<br />
<br />
==== A Word of Caution ====<br />
<br />
Because of the way we define operations in <math>\mathbb{Z}_n</math>, it is important to check that these operations are well-defined. This is because each of the sets that make up <math>\mathbb{Z}_n</math> contains many different numbers, and therefore has many different names. For example, observe that in <math>\mathbb{Z}_7</math>, we have <math>\overline{1} = \overline{8}</math> and <math>\overline{2} = \overline{9}</math>. It is reasonable to expect that if we perform the addition <math>\overline{8} + \overline{9}</math>, we should get the same answer as if we compute <math>\overline{1} + \overline{2}</math>, since we are simply using different names for the same objects. Indeed, the first addition yields the sum <math>\overline{17} = \overline{3}</math>, which is the same as the result of the second addition.<br />
<br />
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]].<br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
== Intermediate ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4906Modular arithmetic2006-06-27T07:50:55Z<p>Mathjoker: /* Addition, Subtraction, and Multiplication Mod n */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== The Integers Modulo n ===<br />
<br />
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements. For example, if <math>n = 3</math>, then the integers are divided into the following sets:<br />
<br />
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math><br />
<br />
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math><br />
<br />
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math><br />
<br />
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).<br />
<br />
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it. For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>. The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third. The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.<br />
<br />
Instead of thinking of the objects <math>\overline{0}</math>, <math>\overline{1}</math>, and <math>\overline{2}</math> as sets, we can treat them as algebraic objects -- like numbers -- with their own operations of addition and multiplication. Together, these objects form '''the integers modulo <math>3</math>,''' or <math>\mathbb{Z}_3</math>. More generally, if <math>n</math> is a positive integer, then we can define<br />
<br />
<math>\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}</math>,<br />
<br />
where for each <math>k</math>, <math>\overline{k}</math> is defined by<br />
<br />
<math>\overline{k} = \{ m \in \mathbb{Z} \mbox{ such that } m \equiv k \pmod{n} \}.</math><br />
<br />
=== Addition, Subtraction, and Multiplication Mod n ===<br />
<br />
We define addition, subtraction, and multiplication in <math>\mathbb{Z}_n</math> according to the following rules:<br />
<br />
<math>\overline{a} + \overline{b} = \overline{a+b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Addition)<br />
<br />
<math>\overline{a} - \overline{b} = \overline{a-b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Subtraction)<br />
<br />
<math>\overline{a} \cdot \overline{b} = \overline{ab}</math> for all <math>a, b \in \mathbb{Z}</math>. (Multiplication)<br />
<br />
So for example, if <math>n = 7</math>, then we have<br />
<br />
<math>\overline{3} + \overline{2} = \overline{3+2} = \overline{5}</math><br />
<br />
<math>\overline{4} + \overline{4} = \overline{4+4} = \overline{8} = \overline{1}</math><br />
<br />
<math>\overline{4} \cdot \overline{3} = \overline{4 \cdot 3} = \overline{12} = \overline{5}</math><br />
<br />
<math>\overline{6} \cdot \overline{6} = \overline{6 \cdot 6} = \overline{36} = \overline{1}</math><br />
<br />
Notice that, in each case, we reduce to an answer of the form <math>\overline{k}</math>, where <math>0 \leq k < 7</math>. We do this for two reasons: to keep possible future calculations as manageable as possible, and to emphasize the point that each expression takes one of only seven (or in general, <math>n</math>) possible values. (Some people find it useful to reduce an answer such as <math>\overline{5}</math> to <math>\overline{-2}</math>, which is negative but has a smaller absolute value.)<br />
<br />
Observe that we use modular arithmetic even when solving some of the most basic, everyday problems. For example:<br />
<br />
''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?''<br />
<br />
We know that the hours of the day are numbered from <math>1</math> to <math>12</math>, with hours having the same number if and only if they are a multiple of <math>12</math> hours apart. So we can use subtraction mod <math>12</math> to answer this question.<br />
<br />
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<br />
<br />
<math>\overline{2} - \overline{6} = \overline{-4} = \overline{8}.</math><br />
<br />
So Cody must quit studying at 8 AM.<br />
<br />
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 <math>\mathbb{Z}_n</math>: a "number circle." Just as we model addition and subtraction by moving along a number line, we can model addition and subtraction mod <math>n</math> 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.<br />
<br />
==== A Word of Caution ====<br />
<br />
Because of the way we define operations in <math>\mathbb{Z}_n</math>, it is important to check that these operations are well-defined. This is because each of the sets that make up <math>\mathbb{Z}_n</math> contains many different numbers, and therefore has many different names. For example, observe that in <math>\mathbb{Z}_7</math>, we have <math>\overline{1} = \overline{8}</math> and <math>\overline{2} = \overline{9}</math>. It is reasonable to expect that if we perform the addition <math>\overline{8} + \overline{9}</math>, we should get the same answer as if we compute <math>\overline{1} + \overline{2}</math>, since we are simply using different names for the same objects. Indeed, the first addition yields the sum <math>\overline{17} = \overline{3}</math>, which is the same as the result of the second addition.<br />
<br />
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]].<br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
== Intermediate ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4892Modular arithmetic2006-06-27T06:53:56Z<p>Mathjoker: /* Arithmetic Modulo n */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== The Integers Modulo n ===<br />
<br />
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements. For example, if <math>n = 3</math>, then the integers are divided into the following sets:<br />
<br />
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math><br />
<br />
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math><br />
<br />
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math><br />
<br />
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).<br />
<br />
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it. For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>. The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third. The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.<br />
<br />
Instead of thinking of the objects <math>\overline{0}</math>, <math>\overline{1}</math>, and <math>\overline{2}</math> as sets, we can treat them as algebraic objects -- like numbers -- with their own operations of addition and multiplication. Together, these objects form '''the integers modulo <math>3</math>,''' or <math>\mathbb{Z}_3</math>. More generally, if <math>n</math> is a positive integer, then we can define<br />
<br />
<math>\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}</math>,<br />
<br />
where for each <math>k</math>, <math>\overline{k}</math> is defined by<br />
<br />
<math>\overline{k} = \{ m \in \mathbb{Z} \mbox{ such that } m \equiv k \pmod{n} \}.</math><br />
<br />
=== Addition, Subtraction, and Multiplication Mod n ===<br />
<br />
We define addition, subtraction, and multiplication in <math>\mathbb{Z}_n</math> according to the following rules:<br />
<br />
<math>\overline{a} + \overline{b} = \overline{a+b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Addition)<br />
<br />
<math>\overline{a} - \overline{b} = \overline{a-b}</math> for all <math>a, b \in \mathbb{Z}</math>. (Subtraction)<br />
<br />
<math>\overline{a} \cdot \overline{b} = \overline{ab}</math> for all <math>a, b \in \mathbb{Z}</math>. (Multiplication)<br />
<br />
So for example, if <math>n = 7</math>, then we have<br />
<br />
<math>\overline{3} + \overline{2} = \overline{3+2} = \overline{5}</math><br />
<br />
<math>\overline{4} + \overline{4} = \overline{4+4} = \overline{8} = \overline{1}</math><br />
<br />
<math>\overline{4} \cdot \overline{3} = \overline{4 \cdot 3} = \overline{12} = \overline{5}</math><br />
<br />
<math>\overline{6} \cdot \overline{6} = \overline{6 \cdot 6} = \overline{36} = \overline{1}</math><br />
<br />
Notice that, in each case, we reduce to an answer of the form <math>\overline{k}</math>, where <math>0 \leq k < 7</math>. We do this for two reasons: to keep possible future calculations as manageable as possible, and to emphasize the point that each expression takes one of only seven (or in general, <math>n</math>) possible values. (Some people find it useful to reduce an answer such as <math>\overline{5}</math> to <math>\overline{-2}</math>, which is negative but has a smaller absolute value.)<br />
<br />
Because of the way we define operations in <math>\mathbb{Z}_n</math>, it is important to check that these operations are well-defined. This is because each of the sets that make up <math>\mathbb{Z}_n</math> contains many different numbers, and therefore has many different names. For example, observe that in <math>\mathbb{Z}_7</math>, we have <math>\overline{1} = \overline{8}</math> and <math>\overline{2} = \overline{9}</math>. It is reasonable to expect that if we perform the addition <math>\overline{8} + \overline{9}</math>, we should get the same answer as if we compute <math>\overline{1} + \overline{2}</math>, since we are simply using different names for the same objects. Indeed, the first addition yields the sum <math>\overline{17} = \overline{3}</math>, which is the same as the result of the second addition.<br />
<br />
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]].<br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
== Intermediate ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4891Modular arithmetic2006-06-27T06:36:51Z<p>Mathjoker: /* Arithmetic Modulo n */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== The Integers Modulo n ===<br />
<br />
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements. For example, if <math>n = 3</math>, then the integers are divided into the following sets:<br />
<br />
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math><br />
<br />
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math><br />
<br />
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math><br />
<br />
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).<br />
<br />
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it. For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>. The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third. The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.<br />
<br />
Instead of thinking of the objects <math>\overline{0}</math>, <math>\overline{1}</math>, and <math>\overline{2}</math> as sets, we can treat them as algebraic objects -- like numbers -- with their own operations of addition and multiplication. Together, these objects form '''the integers modulo <math>3</math>,''' or <math>\mathbb{Z}_3</math>. More generally, if <math>n</math> is a positive integer, then we can define<br />
<br />
<math>\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}</math>,<br />
<br />
where for each <math>k</math>, <math>\overline{k}</math> is defined by<br />
<br />
<math>\overline{k} = \{ m \in \mathbb{Z} \mbox{ such that } m \equiv k \pmod{n} \}.</math><br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
== Intermediate ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4890Modular arithmetic2006-06-27T06:35:02Z<p>Mathjoker: /* The Integers Modulo n */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== The Integers Modulo n ===<br />
<br />
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements. For example, if <math>n = 3</math>, then the integers are divided into the following sets:<br />
<br />
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math><br />
<br />
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math><br />
<br />
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math><br />
<br />
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).<br />
<br />
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it. For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>. The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third. The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.<br />
<br />
Instead of thinking of the objects <math>\overline{0}</math>, <math>\overline{1}</math>, and <math>\overline{2}</math> as sets, we can treat them as algebraic objects -- like numbers -- with their own operations of addition and multiplication. Together, these objects form '''the integers modulo <math>3</math>,''' or <math>\mathbb{Z}_3</math>. More generally, if <math>n</math> is a positive integer, then we can define<br />
<br />
<math>\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}</math>,<br />
<br />
where for each <math>k</math>, <math>\overline{k}</math> is defined by<br />
<br />
<math>\overline{k} = \{ m \in \mathbb{Z} \mbox{ such that } m \equiv k \pmod{n} \}.</math><br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
== Intermediate ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4889Modular arithmetic2006-06-27T06:32:21Z<p>Mathjoker: /* Arithmetic Modulo n */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
<br />
=== The Integers Modulo n ===<br />
<br />
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements. For example, if <math>n = 3</math>, then the integers are divided into the following sets:<br />
<br />
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math><br />
<br />
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math><br />
<br />
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math><br />
<br />
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).<br />
<br />
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it. For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>. The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third. The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.<br />
<br />
Instead of thinking of the objects <math>\overline{0}</math>, <math>\overline{1}</math>, and <math>\overline{2}</math> as sets, we can treat them as algebraic objects -- like numbers -- with their own operations of addition and multiplication. Together, these objects form '''the integers modulo <math>3</math>,''' or <math>\mathbb{Z}_3</math>. More generally, if <math>n</math> is a positive integer, then we can define<br />
<br />
<math>\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}.</math><br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
== Intermediate ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4888Modular arithmetic2006-06-27T06:25:36Z<p>Mathjoker: /* Introductory */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Arithmetic Modulo n ==<br />
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements. For example, if <math>n = 3</math>, then the integers are divided into the following sets:<br />
<br />
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math><br />
<br />
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math><br />
<br />
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math><br />
<br />
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).<br />
<br />
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it. For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>. The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third. The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.<br />
<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
=== Applications ===<br />
<br />
Modular arithmetic is an extremely useful tool in mathematics competitions. It enables us to easily solve [[Linear Diophantine equation]]s, and it often helps with other [[Diophantine equation | Diophantine equations]] as well.<br />
<br />
== Intermediate ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4588Modular arithmetic2006-06-25T01:18:39Z<p>Mathjoker: /* Useful Facts */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Introductory ==<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
=== Applications ===<br />
<br />
Modular arithmetic is an extremely useful tool in mathematics competitions. It enables us to easily solve [[Linear Diophantine equation]]s, and it often helps with other [[Diophantine equation | Diophantine equations]] as well.<br />
<br />
== Intermediate ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4587Modular arithmetic2006-06-25T01:17:01Z<p>Mathjoker: /* Intermediate */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Introductory ==<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Substraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
=== Applications ===<br />
<br />
Modular arithmetic is an extremely useful tool in mathematics competitions. It enables us to easily solve [[Linear Diophantine equation]]s, and it often helps with other [[Diophantine equation | Diophantine equations]] as well.<br />
<br />
== Intermediate ==<br />
<br />
=== Divisibility Tests ===<br />
<br />
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by <math>9</math>:<br />
<br />
''Let <math>N</math> be a positive integer. Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''<br />
<br />
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:<br />
<br />
Suppose that the base-ten representation of <math>N</math> is<br />
<br />
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,<br />
<br />
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by<br />
<br />
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.<br />
<br />
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.<br />
<br />
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write<br />
<br />
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).<br />
<br />
Therefore, we have<br />
<br />
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).<br />
<br />
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>. It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.<br />
<br />
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>. We can also use the technique shown above to devise a test for divisibility by <math>11</math>.<br />
<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4585Modular arithmetic2006-06-25T01:04:31Z<p>Mathjoker: /* Computation of Powers Mod n */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Introductory ==<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Substraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
=== Applications ===<br />
<br />
Modular arithmetic is an extremely useful tool in mathematics competitions. It enables us to easily solve [[Linear Diophantine equation]]s, and it often helps with other [[Diophantine equation | Diophantine equations]] as well.<br />
<br />
== Intermediate ==<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4524Modular arithmetic2006-06-24T19:22:38Z<p>Mathjoker: /* Introductory */</p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Introductory ==<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Substraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Computation of Powers Mod n ===<br />
<br />
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>. Consider, for example, the problem<br />
<br />
''What are the tens and units digits of <math>7^{1942}</math>?''<br />
<br />
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>.<br />
<br />
By writing down the first few powers of <math>7</math>, 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<br />
<br />
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).<br />
<br />
By the "Multiplication" property above, then, it follows that<br />
<br />
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).<br />
<br />
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>. Since both integers are positive, this means that they share the same tens and units digits. Those digits are <math>4</math> and <math>9</math>, respectively.<br />
<br />
=== Applications ===<br />
<br />
Modular arithmetic is an extremely useful tool in mathematics competitions. It enables us to easily solve [[Linear Diophantine equation]]s, and it often helps with other [[Diophantine equation | Diophantine equations]] as well.<br />
<br />
== Intermediate ==<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4523Modular arithmetic2006-06-24T19:05:24Z<p>Mathjoker: </p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Introductory ==<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Substraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Applications ===<br />
<br />
Modular arithmetic is an extremely useful tool in mathematics competitions. It enables us to easily solve [[Linear Diophantine equation]]s, and it often helps with other [[Diophantine equation | Diophantine equations]] as well.<br />
<br />
== Intermediate ==<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]<br />
<br />
== Miscellany ==<br />
<br />
=== The binary operation "mod" ===<br />
<br />
Related to the concept of congruence mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.<br />
<br />
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>. The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''. The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>. For example:<br />
<br />
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.<br />
<br />
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.<br />
<br />
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.<br />
<br />
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Equivalence_relation&diff=4410Equivalence relation2006-06-24T02:20:20Z<p>Mathjoker: </p>
<hr />
<div>Let <math>S</math> be a set. A relation <math>\sim</math> on <math>S</math> is said to be an ''equivalence relation'' if <math>\sim</math> satisfies the following three properties:<br />
<br />
1. For every element <math>x \in S</math>, <math>x \sim x</math>. (Reflexive property)<br />
<br />
2. If <math>x, y \in S</math> such that <math>x \sim y</math>, then we also have <math>y \sim x</math>. (Symmetric property)<br />
<br />
3. If <math>x, y, z \in S</math> such that <math>x \sim y</math> and <math>y \sim z</math>, then we also have <math>x \sim z</math>. (Transitive property)<br />
<br />
Some common examples of equivalence relations:<br />
<br />
* The relation <math>=</math> (equality), on the set of real numbers.<br />
* The relation <math>\cong</math> (congruence), on the set of geometric figures in the plane.<br />
* The relation <math>\sim</math> (similarity), on the set of geometric figures in the plane.<br />
* For a given positive integer <math>n</math>, the relation <math>\equiv</math> (mod <math>n</math>), on the set of integers. ([[Modular arithmetic|Congruence mod n]])</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Equivalence_relation&diff=4409Equivalence relation2006-06-24T02:20:02Z<p>Mathjoker: </p>
<hr />
<div>Let <math>S</math> be a set. A relation <math>\sim</math> on <math>S</math> is said to be an ''equivalence relation'' if <math>\sim</math> satisfies the following three properties:<br />
<br />
1. For every element <math>x \in S</math>, <math>x \sim x</math>. (Reflexive property)<br />
<br />
2. If <math>x, y \in S</math> such that <math>x \sim y</math>, then we also have <math>y \sim x</math>. (Symmetric property)<br />
<br />
3. If <math>x, y, z \in S</math> such that <math>x \sim y</math> and <math>y \sim z</math>, then we also have <math>x \sim z</math>. (Transitive property)<br />
<br />
Some common examples of equivalence relations:<br />
<br />
* The relation <math>=</math> (equality), on the set of real numbers.<br />
* The relation <math>\cong</math> (congruence), on the set of geometric figures in the plane.<br />
* The relation <math>\sim</math> (similarity), on the set of geometric figures in the plane.<br />
* For a given positive integer <math>n</math>, the relation <math>\equiv</math> (mod <math>n</math>), on the set of integers. ([[Modular arithmetic|Congruence mod <math>n</math>]])</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Equivalence_relation&diff=4408Equivalence relation2006-06-24T02:18:40Z<p>Mathjoker: </p>
<hr />
<div>Let <math>S</math> be a set. A relation <math>\sim</math> on <math>S</math> is said to be an ''equivalence relation'' if <math>\sim</math> satisfies the following three properties:<br />
<br />
1. For every element <math>x \in S</math>, <math>x \sim x</math>. (Reflexive property)<br />
<br />
2. If <math>x, y \in S</math> such that <math>x \sim y</math>, then we also have <math>y \sim x</math>. (Symmetric property)<br />
<br />
3. If <math>x, y, z \in S</math> such that <math>x \sim y</math> and <math>y \sim z</math>, then we also have <math>x \sim z</math>. (Transitive property)<br />
<br />
Some common examples of equivalence relations:<br />
<br />
* The relation <math>=</math> (equality), on the set of real numbers.<br />
* The relation <math>\cong</math> (congruence), on the set of geometric figures in the plane.<br />
* The relation <math>\sim</math> (similarity), on the set of geometric figures in the plane.<br />
* For a given positive integer <math>n</math>, the relation <math>\equiv</math> (mod <math>n</math>), on the set of integers. (Congruence mod <math>n</math>)</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Equivalence_relation&diff=4407Equivalence relation2006-06-24T02:18:00Z<p>Mathjoker: </p>
<hr />
<div>Let <math>S</math> be a set. A relation <math>\sim</math> on <math>S</math> is said to be an ''equivalence relation'' if <math>\sim</math> satisfies the following three properties:<br />
<br />
1. For every element <math>x \in S</math>, <math>x \sim x</math>. (Reflexive property)<br />
<br />
2. If <math>x, y \in S</math> such that <math>x \sim y</math>, then we also have <math>y \sim x</math>. (Symmetric property)<br />
<br />
3. If <math>x, y, z \in S</math> such that <math>x \sim y</math> and <math>y \sim z</math>, then we also have <math>x \sim z</math>. (Transitive property)<br />
<br />
Some common examples of equivalence relations:<br />
<br />
* The relation <math>=</math> (equality), on the set of real numbers.<br />
* The relation <math>\cong</math> (congruence), on the set of geometric figures in the plane.<br />
* The relation <math>\sim</math> (similarity), on the set of geometric figures in the plane.<br />
* For a given positive integer <math>n</math>, the relation <math>\equiv</math> (mod <math>n</math>), on the set of integers.</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Equivalence_relation&diff=4406Equivalence relation2006-06-24T02:17:42Z<p>Mathjoker: </p>
<hr />
<div>Let <math>S</math> be a set. A relation <math>\sim</math> on <math>S</math> is said to be an ''equivalence relation'' if <math>\sim</math> satisfies the following three properties:<br />
<br />
1. For every element <math>x \in S</math>, <math>x \sim x</math>. (Reflexive property)<br />
2. If <math>x, y \in S</math> such that <math>x \sim y</math>, then we also have <math>y \sim x</math>. (Symmetric property)<br />
3. If <math>x, y, z \in S</math> such that <math>x \sim y</math> and <math>y \sim z</math>, then we also have <math>x \sim z</math>. (Transitive property)<br />
<br />
Some common examples of equivalence relations:<br />
<br />
* The relation <math>=</math> (equality), on the set of real numbers.<br />
* The relation <math>\cong</math> (congruence), on the set of geometric figures in the plane.<br />
* The relation <math>\sim</math> (similarity), on the set of geometric figures in the plane.<br />
* For a given positive integer <math>n</math>, the relation <math>\equiv</math> (mod <math>n</math>), on the set of integers.</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4394Modular arithmetic2006-06-24T01:55:06Z<p>Mathjoker: </p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Introductory ==<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Substraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Applications ===<br />
<br />
Modular arithmetic is an extremely useful tool in mathematics competitions. It enables us to easily solve [[Linear Diophantine equation]]s, and it often helps with other [[Diophantine equation | Diophantine equations]] as well.<br />
<br />
== Intermediate ==<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4388Modular arithmetic2006-06-24T01:52:38Z<p>Mathjoker: </p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Introductory ==<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Substraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Applications ===<br />
<br />
Modular arithmetic is an extremely useful tool in mathematics competitions. It enables us to easily solve [[Linear diophantine equation]]s, and it often helps with other [[Diophantine equation | Diophantine equations]] as well.<br />
<br />
<br />
<br />
== Intermediate ==<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4385Modular arithmetic2006-06-24T01:52:20Z<p>Mathjoker: </p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers. This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>, or <math>\mathbb{Z}_n</math> for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.<br />
<br />
<br />
== Introductory ==<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Substraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Applications ===<br />
<br />
Modular arithmetic is an extremely useful tool in mathematics competitions. It enables us to easily solve [[Linear diophantine equation]]s, and it often helps with other [[Diophantine equation | Diophantine equations]] as well.<br />
<br />
<br />
<br />
== Intermediate ==<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic&diff=4381Modular arithmetic2006-06-24T01:47:00Z<p>Mathjoker: </p>
<hr />
<div>'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]]. Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.<br />
<br />
<br />
== Introductory ==<br />
=== Useful Facts ===<br />
<br />
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:<br />
<br />
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.<br />
* Substraction: <math>a-c\equiv b-d\pmod {m}</math>.<br />
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.<br />
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.<br />
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.<br />
<br />
=== Examples ===<br />
<br />
* <math>{7}\equiv {1} \pmod {2}</math><br />
<br />
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math><br />
<br />
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math><br />
<br />
=== Applications ===<br />
<br />
Modular arithmetic is an extremely useful tool in mathematics competitions. It enables us to easily solve [[Linear diophantine equation]]s, and it often helps with other [[Diophantine equation | Diophantine equations]] as well.<br />
<br />
<br />
<br />
== Intermediate ==<br />
=== Topics ===<br />
* [[Fermat's Little Theorem]]<br />
* [[Euler's Totient Theorem]]<br />
* [[Phi function]]<br />
<br />
=== See also ===<br />
<br />
* [[Number theory]]<br />
* [[Quadratic residues]]</div>Mathjokerhttps://artofproblemsolving.com/wiki/index.php?title=National_Online_Math_League&diff=3627National Online Math League2006-06-21T14:58:39Z<p>Mathjoker: </p>
<hr />
<div>The '''National Online Math League''' ('''NOML'''), formerly known as the '''Cody Bowl''' is a highly unique and challenging [[mathematics competition]] for high school and college students.<br />
<br />
== History of NOML ==<br />
The National Online Math League / Cody Bowl has a tumultuous history that mirrors the often chaotic life of its founder. The league has gone through two name changes, two very different formats, and two cancellations.<br />
<br />
=== The first two seasons ===<br />
In its first season, NOML took the form of ''The Weekend Games'', held at the Texas Mathworks Honors Summer Math Camp for high school students in 2002. The first season consisted of three friendly matches between two teams, which were selected at random for each game. Two of the matches were conducted under a format similar to that used by the [[American Regions Math League]]: a Team test, a Power question, and several Relays. However, one match used an experimental format that included a round similar to the Guts Round held at the [[Harvard-MIT Mathematics Tournament]].<br />
<br />
The Weekend Games returned to the Honors Summer Math Camp for 2003 with a more rigid format, and for the first time, the event was officially known as "Cody Bowl." Each weekend match was a miniature ARML competition between two teams. However, individual statistics were kept on a cumulative basis, and the top eight individuals were invited to compete in a final round of individual competition. In the ''Endurance Round'', the field of eight was narrowed to three in an elimination contest in which a player was required to answer a series of individual questions in order to survive. The final three contestants advanced to ''The Last Stand'', a competition that Patterson proudly claimed "had nothing to do with mathematics whatsoever." Preparation for The Last Stand took league officials over two weeks and a total of more than fifty dollars' worth of lumber and building accessories. The individual champion of the summer series was '''Jeff Nanney''' of Plano, Texas; the prize for first place was an all-expenses-paid dinner at the local Outback Steakhouse and the right to keep the '''Kitchenware Cup''', the official Cody Bowl trophy, for one year.<br />
<br />
The 2003 edition of Cody Bowl, and its newfound focus on individual competition, created a controversy within the camp, and it became clear to Patterson that the games would not be allowed at the camp in the future. Faced with a choice between changing the format of the contest substantially, or retiring it altogether, Patterson chose the option that would best allow him to stick it to "the man."<br />
<br />
=== NOML / Cody Bowl: The Online Math League ===<br />
<br />
=== The Future of NOML ===<br />
<br />
== Resources ==<br />
* [http://www.noml.org/ NOML homepage]<br />
* [http://www.artofproblemsolving.com/Forum/forum-304.html NOML Forum]<br />
* [[Mathematics competition resources]]</div>Mathjoker