https://artofproblemsolving.com/wiki/api.php?action=feedcontributions&user=Roseylily&feedformat=atomAoPS Wiki - User contributions [en]2024-03-29T08:31:20ZUser contributionsMediaWiki 1.31.1https://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic/Intermediate&diff=74772Modular arithmetic/Intermediate2016-01-23T22:35:25Z<p>Roseylily: /* Miscellaneous */</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 />
=== 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 />
* [[Euler's totient function]]<br />
* [[Chicken McNugget Theorem]]<br />
<br />
== Miscellaneous ==<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 <math>e_i</math> when substituted for <math>d_i</math> 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>d_i - f_i</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= 2d_1 +3d_2 +1d_3 -2d_4 -3d_5 -d_6 +2d_7 +3d_8 +d_9 </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 />
== 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]]<br />
<br />
<br />
<br />
<br />
[[Category:Intermediate Mathematics Topics]]</div>Roseylilyhttps://artofproblemsolving.com/wiki/index.php?title=Modular_arithmetic/Introduction&diff=74771Modular arithmetic/Introduction2016-01-23T21:15:37Z<p>Roseylily: /* Problem #3 */</p>
<hr />
<div>'''[[Modular arithmetic]]''' is a special type of arithmetic that involves only [[integers]]. This goal of this article is to explain the basics of modular arithmetic while presenting a progression of more difficult and more interesting problems that are easily solved using modular arithmetic.<br />
<br />
<br />
<br />
== Motivation ==<br />
Let's use a clock as an example, except let's replace the <math>12</math> at the top of the clock with a <math>0</math>. <br />
<br />
<asy>picture pic;<br />
path a;<br />
a = circle((0,0), 100);<br />
draw (a);<br />
draw((0,0), linewidth(4));<br />
<br />
pair b;<br />
b = (0,100);<br />
<br />
for (int i = 0; i < 12; ++i)<br />
{<br />
label (pic, (string) i, b);<br />
b = rotate(-30,(0,0)) * b;<br />
}<br />
pic = scale(0.8) * pic;<br />
add(pic);<br />
<br />
draw ((0,0) -- 50*dir(90));<br />
draw ((0,0) -- 70*dir(90));</asy><br />
<br />
Starting at noon, the hour hand points in order to the following:<br />
<br />
<math>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>1</math> to <math>11</math>, we arrive back at <math>0</math>. The same is true in any other [[modulus]] (modular arithmetic system). In modulo <math>5</math>, we [[counting | count]]<br />
<br />
<br />
<math>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>-12</math> to <math>0</math>, when written in modulo 5, are<br />
<br />
<br />
<math>3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0,</math><br />
<br />
<br />
where <math>-12</math> is the same as <math>3</math> in modulo 5. Because all integers can be expressed as <math>0</math>, <math>1</math>, <math>2</math>, <math>3</math>, or <math>4</math> in modulo 5, we give these integers their own name: the '''[[residue class]]es''' modulo 5. In general, for a natural number <math>n</math> that is greater than 1, the modulo <math>n</math> residues are the integers that are [[whole number | whole numbers]] less than <math>n</math>:<br />
<br />
<br />
<math>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 />
==Residue==<br />
We say that <math>a</math> is the modulo-<math>m</math> <b>residue</b> of <math>n</math> when <math>n\equiv a\pmod m</math>, and <math>0\le a<m</math>.<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>\equiv</math>: In other words, this means in base 5, these integers have the same last digit:<br />
<br />
2(base 5) <math> \equiv </math> 12(base 5) <math> \equiv </math> 22(base 5) <math> \equiv </math> 32(base 5) <math> \equiv </math> 42(base 5)<br />
<br />
<br />
<center><math>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>-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>a</math> and <math>b</math> are congruent modulo <math>n</math> when <math>a - b</math> is a multiple of <math>n</math>. In other words, <math>a \equiv b \pmod{n}</math> when <math>\frac{a-b}{n}</math> is an integer. Otherwise, <math>a \not\equiv b \pmod{n}</math>, which means that <math>a</math> and <math>b</math> are '''not congruent''' modulo <math>n</math>.<br />
<br />
<br />
<br />
=== Examples ===<br />
* <math>31 \equiv 1 \pmod{10}</math> because <math>31 - 1 = 30</math> is a multiple of <math>10</math>.<br />
<br />
<br />
* <math>43 \equiv 22 \pmod{7}</math> because <math>\frac{43 - 22}{7} = \frac{21}{7} = 3</math>, which is an integer.<br />
<br />
<br />
* <math>8 \not\equiv -8 \pmod{3}</math> because <math>8 - (-8) = 16</math>, which is not a multiple of <math>3</math>.<br />
<br />
<br />
* <math>91 \not\equiv 18 \pmod{6}</math> because <math>\frac{91 - 18}{6} = \frac{73}{6}</math>, which is not an integer.<br />
<br />
<br />
<br />
=== Sample Problem ===<br />
Find the modulo <math>4</math> residue of <math>311</math>.<br />
==== Solution: ====<br />
Since <math>311 \div 4 = 77</math> R <math>3</math>, we know that <br />
<center><math>311 \equiv 3 \pmod{4}</math></center><br />
and <math>3</math> is the modulo <math>4</math> residue of <math>311</math>.<br />
<br />
==== Another Solution: ====<br />
Since <math> 311 = 300 + 11 </math>, we know that<br />
<center><math>311 \equiv 0+11 \pmod{4}</math></center><br />
We can now solve it easily<br />
<center><math>11 \equiv 3 \pmod{4}</math></center><br />
and <math>3</math> is the modulo <math>4</math> residue of <math>311</math><br />
<br />
== Making Computation Easier ==<br />
We don't always need to perform tedious computations to discover solutions to interesting problems. If all we need to know about are remainders when integers are divided by <math>n</math>, then we can work directly with those remainders in modulo <math>n</math>. This can be more easily understood with a few examples.<br />
<br />
=== Addition ===<br />
==== Problem ====<br />
Suppose we want to find the [[units digit]] of the following [[sum]]:<br />
<br />
<br />
<center><math>2403 + 791 + 688 + 4339.</math></center><br />
<br />
<br />
We could find their sum, which is <math>8221</math>, and note that the units digit is <math>1</math>. However, we could find the units digit with far less calculation.<br />
<br />
==== Solution ====<br />
We can simply add the units digits of the addends:<br />
<br />
<br />
<center><math>3 + 1 + 8 + 9 = 21.</math></center><br />
<br />
<br />
The units digit of this sum is <math>1</math>, which ''must'' be the same as the units digit of the four-digit sum we computed earlier.<br />
<br />
==== Why we only need to use remainders ====<br />
We can rewrite each of the integers in terms of multiples of <math>10</math> and remainders:<br><br />
<math>2403 = 240 \cdot 10 + 3</math><br><br />
<math>791 = 79 \cdot 10 + 1</math><br><br />
<math>688 = 68 \cdot 10 + 8</math><br><br />
<math>4339 = 433 \cdot 10 + 9</math>.<br><br />
When we add all four integers, we get<br />
<br />
<br />
<center><math> (240 \cdot 10 + 3) + (79 \cdot 10 + 1) + (68 \cdot 10 + 8) + (433 \cdot 10 + 9)</math></center><br />
<br />
<center><math>= (240 + 79 + 68 + 433) \cdot 10 + (3 + 1 + 8 + 9)</math></center><br />
<br />
<br />
At this point, we already see the units digits grouped apart and added to a multiple of <math>10</math> (which will not affect the units digit of the sum):<br />
<br />
<center><math>= 820 \cdot 10 + 21 = 8200 + 21 = 8221</math>.</center><br />
<br />
==== Solution using modular arithmetic ====<br />
Now let's look back at this solution, using modular arithmetic from the start. Note that<br><br />
<math>2403 \equiv 3 \pmod{10}</math><br><br />
<math>791 \equiv 1 \pmod{10}</math><br><br />
<math>688 \equiv 8 \pmod{10}</math><br><br />
<math>4339 \equiv 9 \pmod{10}</math><br><br />
Because we only need the modulo <math>10</math> residue of the sum, we add just the residues of the summands:<br />
<br />
<center><math>2403 + 791 + 688 + 4339 \equiv 3 + 1 + 8 + 9 \equiv 21 \equiv 1 \pmod{10},</math></center><br />
so the units digit of the sum is just <math>1</math>.<br />
<br />
==== Addition rule ====<br />
In general, when <math>a, b, c</math>, and <math>d</math> are integers and <math>m</math> is a positive integer such that<br><br />
<center><math>a \equiv c \pmod{m} </math></center><br />
<center><math>b \equiv d \pmod{m} </math></center><br />
the following is always true:<br />
<br />
<center><math>a + b \equiv c + d \pmod{m} </math>.</center><br />
And as we did in the problem above, we can apply more pairs of equivalent integers to both sides, just repeating this simple principle.<br />
<br />
====Proof of the addition rule====<br />
<br />
Let <math>a-c=m\cdot k</math>, and <math>b-d=m\cdot l</math> where <math>l</math> and <math>k</math> are integers. <br />
Adding the two equations we get:<br />
<cmath><br />
\begin{eqnarray*}<br />
mk+ml&=&(a-c)+(b-d)\\<br />
m(k+l)&=&(a+b)-(c+d)<br />
\end{eqnarray*}<br />
</cmath><br />
<br />
Which is equivalent to saying <math>a+b\equiv c+d\pmod{m}</math><br />
<br />
=== Subtraction ===<br />
The same shortcut that works with addition of remainders works also with subtraction.<br />
<br />
==== Problem ====<br />
Find the remainder when the difference between <math>60002</math> and <math>601</math> is divided by <math>6</math>.<br />
<br />
==== Solution ====<br />
Note that <math>60002 = 10000 \cdot 6 + 2</math> and <math>601 = 100 \cdot 6 + 1</math>. So,<br><br />
<math>60002 \equiv 2 \pmod{6}</math><br><br />
<math>601 \equiv 1 \pmod{6}</math><br><br />
Thus,<br />
<center><math>60002 - 601 \equiv 2 - 1 \equiv 1 \pmod{6}, </math></center><br />
so 1 is the remainder when the difference is divided by <math>6</math>. (Perform the subtraction yourself, divide by <math>6</math>, and see!)<br />
<br />
==== Subtraction rule ====<br />
When <math>a, b, c</math>, and <math>d</math> are integers and <math>m</math> is a positive integer such that<br><br />
<center><math>a \equiv c \pmod{m} </math></center><br />
<center><math>b \equiv d \pmod{m} </math></center><br />
the following is always true:<br />
<br />
<center><math>a - b \equiv c - d \pmod{m} </math></center>.<br />
<br />
<br />
=== Multiplication ===<br />
Modular arithmetic provides an even larger advantage when multiplying than when adding or subtracting. Let's take a look at a problem that demonstrates the point.<br />
<br />
==== Problem ====<br />
Jerry has 44 boxes of soda in his truck. The cans of soda in each box are packed oddly so that there are 113 cans of soda in each box. Jerry plans to pack the sodas into cases of 12 cans to sell. After making as many complete cases as possible, how many sodas will Jerry have leftover?<br />
<br />
==== Solution ====<br />
First, we note that this [[word problem]] is asking us to find the remainder when the product <math>44 \cdot 113</math> is divided by <math>12</math>.<br />
<br />
Now, we can write each <math>44</math> and <math>113</math> in terms of multiples of <math>12</math> and remainders:<br><br />
<math>44 = 3 \cdot 12 + 8</math><br><br />
<math>113 = 9 \cdot 12 + 5</math><br><br />
This gives us a nice way to view their product:<br />
<br />
<br />
<cmath>44 \cdot 113 = (3 \cdot 12 + 8)(9 \cdot 12 + 5)</cmath><br />
Using [[FOIL]], we get that this equals<br />
<cmath>(3 \cdot 9) \cdot 12^2 + (3 \cdot 5 + 8 \cdot 9) \cdot 12 + (8 \cdot 5)</cmath><br />
<br />
<br />
We can already see that each part of the product is a multiple of <math>12</math>, except the product of the remainders when each <math>44</math> and <math>113</math> are divided by 12. That part of the product is <math>8 \cdot 5 = 40</math>, which leaves a remainder of <math>4</math> when divided by <math>12</math>. So, Jerry has <math>4</math> sodas leftover after making as many cases of <math>12</math> as possible.<br />
<br />
==== Solution using modular arithmetic ====<br />
First, we note that<br><br />
<math>44 \equiv 8 \pmod{12}</math><br><br />
<math>113 \equiv 5 \pmod{12}</math><br><br />
Thus,<br />
<center><math>44 \cdot 113 \equiv 8 \cdot 5 \equiv 40 \equiv 4 \pmod{12},</math></center><br />
meaning there are <math>4</math> sodas leftover. Yeah, that was much easier.<br />
<br />
==== Multiplication rule ====<br />
When <math>a, b, c</math>, and <math>d</math> are integers and <math>m</math> is a positive integer such that<br><br />
<center><math>a \equiv c \pmod{m} </math></center><br />
<center><math>b \equiv d \pmod{m} </math></center><br />
The following is always true:<br />
<br />
<center><math>a \cdot b \equiv c \cdot d \pmod{m} </math>.</center><br />
<br />
<br />
=== Exponentiation ===<br />
Since [[exponentiation]] is just repeated multiplication, it makes sense that modular arithmetic would make many problems involving exponents easier. In fact, the advantage in computation is even larger and we explore it a great deal more in the [[intermediate modular arithmetic]] article.<br />
<br />
Note to everybody: Exponentiation is very useful as in the following problem:<br />
<br />
==== Problem #1====<br />
What is the last digit of <math>(...((7)^7)^7)...)^7</math> if there are 1000 7s as exponents and only one 7 in the middle?<br />
<br />
We could solve this problem using mods. This can also be stated as <math>7^{7^{1000}}</math>. After that, we see that 7 is congruent to -1 in mod 4, so we can use this fact to replace the 7s with -1s, because 7 has a pattern of repetitive period 4 for the units digit. <math>(-1)^{1000}</math> is simply 1, so therefore <math>7^1=7</math>, which really is the last digit.<br />
<br />
==== Problem #2====<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 />
==== Problem #3====<br />
<br />
Can you find a number that is both a multiple of <math>2</math> but not a multiple of <math>4</math> and a perfect square?<br />
<br />
No, you cannot. Rewriting the question, we see that it asks us to find an integer <math>n</math> that satisfies <math>4n+2=x^2</math>.<br />
<br />
Taking mod <math>4</math> on both sides, we find that <math>x^2\equiv 2\pmod{4}</math>. Now, all we are missing is proof that no matter what <math>x</math> is, <math>x^2</math> will never be a multiple of <math>4</math> plus <math>2</math>, so we work with cases:<br />
<br />
<math>x\equiv 0\pmod{4}\implies x^2\equiv 0\pmod{4}</math><br />
<br />
<math>x\equiv 1\pmod{4}\implies x^2\equiv 1\pmod{4}</math><br />
<br />
<math>x\equiv 2\pmod{4}\implies x^2\equiv 4\equiv 0\pmod{4}</math><br />
<br />
<math>x\equiv 3\pmod{4}\implies x^2\equiv 9\equiv 1\pmod{4}</math><br />
<br />
This assures us that it is impossible to find such a number.<br />
<br />
== Summary of 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 />
== 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/Store/viewitem.php?item=intro:nt Introduction to Number Theory] by [[Mathew Crawford]].<br />
* The AoPS [http://www.artofproblemsolving.com/School/courseinfo.php?course_id=intro:numbertheory Introduction to Number Theory Course]. Thousands of students have learned more about modular arithmetic and [[problem solving]] from this 12 week class.<br />
<br />
== See also ==<br />
* [[Intermediate modular arithmetic]]<br />
* [[Olympiad modular arithmetic]]<br />
<br />
<br />
[[Category:Introductory Mathematics Topics]]</div>Roseylily