<?xml version="1.0" encoding="UTF-8" ?>
  <resource>
  <id>4350</id>
  <path>/www/nrich/html/content/id/4350/</path>
  <resourceTypeID>3</resourceTypeID>
  <last_published>2011-02-01T00:00:01</last_published>
  <indexXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;mdoxml version=&quot;1.0&quot;&gt;&lt;br&gt;&lt;/br&gt;
The best way to introduce modular arithmetic is to think of the face of a clock.
&lt;p style=&quot;text-align: center;&quot;&gt;&lt;mdo:image alt=&quot;Clock face numbered 1--12&quot; height=&quot;217&quot; src=&quot;Clock1.gif&quot; width=&quot;217&quot;&gt;&lt;/mdo:image&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;The numbers go from $1$ to $12$, but when you get to &quot;$13$ o&amp;#39;clock&quot;, it actually becomes $1$ o&amp;#39;clock again (think of how the $24$ hour clock numbering works). So $13$ becomes $1$, $14$ becomes $2$, and so on.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;This can keep going, so when you get to &quot;$25$ o&amp;#39;clock&amp;#39;&amp;#39;, you are actually back round to where $1$ o&amp;#39;clock is on the clock face (and also where $13$ o&amp;#39;clock was too).&lt;/p&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;&lt;mdo:image alt=&quot;Clock face numbered 1--24&quot; height=&quot;217&quot; src=&quot;Clock2.gif&quot; width=&quot;217&quot;&gt;&lt;/mdo:image&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;So in this clock world, you only care where you are in relation to the numbers $1$ to $12$. In this world, $1, 13, 25, 37, \ldots$ are all thought of as the same thing, as are $2, 14, 26, 38, \ldots$ and so on.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;What we are saying is &quot;$13=1+$ some multiple of $12$&quot;, and &quot;$38=2+$ some multiple of $12$&quot;, or, alternatively, &quot;the remainder when you divide $13$ by $12$ is $1$&quot; and &quot;the remainder when you divide $38$ by 12 is 2&amp;#39;&amp;#39;. The way we write this mathematically is $13\equiv 1 \text{ mod } 12$, $38\equiv 2 \text{ mod } 12$, and so on. This is read as &quot;$13$ is congruent to $1$
mod (or modulo) $12$&quot; and &quot;$38$ is congruent to $2 \text{ mod } 12$&quot;.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;But you don&amp;#39;t have to work only in mod $12$ (that&amp;#39;s the technical term for it). For example, you could work mod $7$, or mod $46$ instead if you wanted to (just think of clocks numbered from $1$ to $7$ and $1$ to $46$ respectively; every time you get past the biggest number, you reset to $1$ again).&lt;/p&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;&lt;mdo:image alt=&quot;Clock numbered 0--6&quot; height=&quot;217&quot; src=&quot;Clock3.gif&quot; width=&quot;217&quot;&gt;&lt;/mdo:image&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Let&amp;#39;s go back to the normal clock face with the numbers $1$ to $12$ on it for a moment. Mathematicians usually prefer to put a $0$ where the $12$ would normally be, so that you would usually write (for example) $24\equiv 0 \text{ mod } 12$ rather than $24\equiv 12 \text{ mod } 12$, although both of these are correct. That is, we think of a normal clock face as being
numbered from $0$ to $11$ instead. This makes sense: we&amp;#39;d normally say that $24$ leaves a remainder of $0$ when we divide by $12$, rather than saying it leaves a remainder of $12$ when we divide by $12$!&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Let&amp;#39;s be a bit more formal. In general, if you are working in mod $n$ (where $n$ is any whole number), we write $a\equiv b \text{ mod } n$ if $a$ and $b$ leave the same remainder when you divide them by $n$. This is the same as saying that we write $a\equiv b \text{ mod } n$ if $n$ divides $a-b$. (Look at what we did earlier to see that this definition fits with our
examples above.)&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;So far, we&amp;#39;ve only talked about notation. Now let&amp;#39;s do some maths, and see how congruences (what we&amp;#39;ve described above) can make things a bit clearer.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Here are some useful properties. We can add congruences. That is, if $a\equiv b \text{ mod } n$ and $c\equiv d \text{ mod } n$, then $a+c\equiv (b+d) \text{ mod } n$. Why is this? Well, $a\equiv b \text{ mod } n$ means that $a=b+k n$, where $k$ is an integer. Similarly, $c\equiv d \text{ mod } n$ means that $c=d+l n$, where $l$ is an integer. So $a+c=(b+k n)+(d+l
n)=(b+d)+(k+l)n$, so $a+c\equiv (b+d) \text{ mod } n$. For example, $17\equiv 4 \text{ mod } 13$, and $42\equiv 3 \text{ mod } 13$, so $17+42\equiv 4+3\equiv 7 \text{ mod } 13$. Note that both of the congruences that we&amp;#39;re adding are mod $n$, &lt;span style=&quot;font-style: italic;&quot;&gt;and so is the answer&lt;/span&gt; - we don&amp;#39;t add the moduli.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Now you prove that if $a\equiv b \text{ mod } n$ and $c\equiv d \text{ mod }n$ then $a-c\equiv (b-d) \text{ mod } n$. Also, prove that we can do something similar for multiplication: if $a\equiv b \text{ mod }n$ and $c\equiv d \text{ mod } n$, then $a c\equiv b d \text{ mod } n$. You can prove this in the same way that we used above for addition. Again, both of the
congruences that we&amp;#39;re multiplying are mod $n$, and so is the answer - we don&amp;#39;t multiply the moduli. Can you come up with an example to &lt;span style=&quot;font-style: italic;&quot;&gt;disprove&lt;/span&gt; the claim that $a\equiv b \text{ mod } n$ and $c\equiv d \text{ mod } m$ means that $a c \equiv bd \text{ mod } mn$?&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Division is a bit more tricky: you have to be really careful. Here&amp;#39;s an example of why. $10\equiv 2 \text{ mod } 8$. But if we &quot;divide both sides by 2&quot;, we&amp;#39;d have $5\equiv 1 \text{ mod } 8$, which is clearly nonsense! To get a true congruence, we&amp;#39;d have to divide the $8$ by $2$ as well: $5\equiv 1 \text{ mod } 4$ is fine. Why? Well, $a\equiv b \text{ mod } n$ means
that $a=b+k n$ for some integer $n$. But now this is a normal equation, and if we&amp;#39;re going to divide $a$ by something, then we have to divide &lt;span style=&quot;font-style: italic;&quot;&gt;all&lt;/span&gt; of the right-hand side by $2$ as well, including $k n$. In general, it&amp;#39;s best not to divide congruences; instead, think about what they really mean (rather than using the shorthand) and work from there.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Things are quite special if we work mod $p$, where $p$ is prime, because then each number that isn&amp;#39;t 0 mod $p$ has what we call an &lt;span style=&quot;font-style: italic;&quot;&gt;inverse&lt;/span&gt; (or a &lt;span style=&quot;font-style: italic;&quot;&gt;multiplicative inverse&lt;/span&gt; , if we&amp;#39;re being fancy). What that means is that for each $a\not\equiv 0 \text{ mod } p$, there is a $b$ such that $a
b\equiv 1 \text{ mod } p$.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Let&amp;#39;s think about an example. We&amp;#39;ll work mod $7$. Then really the only non-zero things are $1, 2, 3, 4, 5$ and $6$ (because every other whole number is equivalent to one of them or $0$). So let&amp;#39;s find inverses for them. Well, $1$ is pretty easy: $1\times 1\equiv 1 \text{ mod } 7$. What about $2$? $2\times 4\equiv 1 \text{ mod } 7$. So $4$ is the inverse of $2$. In
fact, we can also see from this that $2$ is the inverse of $4$ - so that&amp;#39;s saved us some work! $3\times 5\equiv 1 \text{ mod } 7$, so $3$ and $5$ are inverses. And finally, $6\times 6\equiv 1 \text{ mod } 7$, so $6$ is the inverse of itself. So yes, each of the non-zero elements mod $7$ has an inverse. Try some primes out yourself: $11$ and $13$ are fairly small! If you&amp;#39;re feeling confident, see
whether you can discover which numbers have inverses mod $4$, or mod $6$, or mod $8$. What about mod $15$? Do you notice any patterns?&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;To prove this, things are going to get a tiny bit more tricky, so I&amp;#39;m going to save the proof for the end and first give an example of using congruences to do useful mathematics.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Suppose we&amp;#39;re given the number $11111111$ and someone asks us whether it&amp;#39;s divisible by $3$. We could try to actually divide it. But you probably know a much easier method: we add up the digits and see whether that&amp;#39;s divisible by $3$. There&amp;#39;s a whole article about this sort of divisibility test &lt;a href=&quot;http://nrich.maths.org/public/viewer.php?obj_id=1308&amp;amp;part=&quot;&gt;here&lt;/a&gt; . Let&amp;#39;s prove this using congruence notation.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Suppose that our number is $a_n 10^n+a_{n-1}10^{n-1}+\ldots+10a_1+a_0$, so it looks like $a_n a_{n-1}\ldots a_1 a_0$. Then the sum of its digits is $a_n+a_{n-1}+\ldots+a_1+a_0$. We&amp;#39;d like to prove that $a_n10^n+a_{n-1}10^{n-1}+\ldots+10a_1+a_0$ is divisible by $3$ if and only if $a_n+a_{n-1}+\ldots+a_1+a_0$ is divisible by $3$. Now we notice that $10\equiv 1 \text{
mod } 3$, so $10\times 10\equiv 1 \text{ mod } 3$, and more generally $10^k\equiv 1 \text{ mod } 3$ for all $k$. Using our results from earlier about adding and multiplying congruences, we discover&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;$$ a_n10^n+a_{n-1}10^{n-1}+\ldots+10a_1+a_0\equiv a_n+a_{n-1}+\ldots+a_1+a_0 \text{ mod } 3 $$ So if our number is divisible by $3$ (that is, if $a_n10^n+a_{n-1}10^{n-1}+\ldots+10a_1+a_0\equiv 0 \text{ mod } 3$), then certainly so is the sum of its digits, and vice versa, as we wanted! The congruence notation hasn&amp;#39;t really done any of the maths for us, but it&amp;#39;s
hopefully made it a bit easier to write out the proof clearly. See whether you can use the notation to prove any of the other divisibility tests in that article.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Now for the proof I promised you earlier. We&amp;#39;re going to show that if $a$ and $n$ have no common factors, then $a$ has a multiplicative inverse mod $n$ (reminder: that means a number $b$ such that $a\times b\equiv 1 \text{ mod } n$). In particular, if $n$ is prime, then its only factor apart from 1 is itself, so saying &quot;$a$ and $n$ share no common factors&amp;#39;&amp;#39; is just
the same as saying &quot;$a$ isn&amp;#39;t divisible by $n$&amp;#39;&amp;#39;, that is, $a\not\equiv 0 \text{ mod } p$: this is what we had above. I&amp;#39;m going to assume that you know about using Euclid&amp;#39;s algorithm to solve equations of the form $a x+b y=1$ where $a$ and $b$ have no common factors. There&amp;#39;s a really good article explaining this &lt;a href=&quot;http://nrich.maths.org/public/viewer.php?obj_id=1357&amp;amp;part=&quot;&gt;here&lt;/a&gt; ,
so have a read, and then come back.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;If you&amp;#39;re reading this far, then hopefully you&amp;#39;ll agree that if $a$ and $n$ share no common factors, then we can find $x$ and $y$ such that $a x+n y=1$. (The fancy name for this is &lt;span style=&quot;font-style: italic;&quot;&gt;Bezout&amp;#39;s Theorem&lt;/span&gt; .) So we&amp;#39;ve got our $x$ and $y$ such that $a x+n y=1$. We can rewrite this as $a x=1-y n$, and now let&amp;#39;s use the congruence
notation from earlier: we have $a x\equiv 1 \text{ mod }n$. So now $x$ is the multiplicative inverse of $a \text{ mod } n$, and we&amp;#39;re done!&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Here&amp;#39;s a challenge: use this technique based on Euclid&amp;#39;s algorithm to find the inverse of $14 \text{ mod } 37$.&lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Understanding this is the beginning of a branch of mathematics called Number Theory, which contains some beautiful, fascinating and amazing theorems. Enjoy!&lt;/p&gt;
&lt;br&gt;&lt;/br&gt;
&lt;p style=&quot;clear: both;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;This article is based on a contribution to Ask NRICH by Matthew Buckley.&lt;/span&gt;&lt;/p&gt;
&lt;br&gt;&lt;/br&gt;&lt;/mdoxml&gt;</indexXML>
  <solutionXML/>
  <noteXML/>
  <clueXML/>
  <canonXML/>
  <end_user_role>5</end_user_role>
  <difficulty>0</difficulty>
  <keystage1>0</keystage1>
  <keystage2>0</keystage2>
  <keystage3>0</keystage3>
  <keystage4>1</keystage4>
  <keystage4plus>0</keystage4plus>
  <title>Modular Arithmetic</title>
  <description>An introduction to the notation and uses of modular arithmetic</description>
  <spec_group>Numbers and the Number System
    <specifier>Number theory</specifier>
  </spec_group>
  <spec_group>Numbers and the Number System
    <specifier>Modulus arithmetic</specifier>
  </spec_group>
</resource>