Summary
In today's class we began by talking about a few "magic tricks" one can do using modular arithmetic. These were motivated by a posting from the forum which showed a video of a "mathemagician" at work. Afterwards we returned to our discussion of Euler's
function from Friday. We first calculated the value of the
function for "special integers," and eventually noticed that the
function obeys some rules which make the calculation of
easy — at least when you have a prime factorization of n.
Magic Tricks and Modular Arithmetic
As a fun beginning to class, we talked a little about some of the magic tricks which are shown in the video from one of the forum threads. Some of these tricks — particularly the presenters ability to square 3-, 4- or 5-digit numbers in his head — come from clever ways of thinking about multiplication together with the skill of performing several small computations without benefit of paper (or, seemingly, time). Others, though, are a bit simpler.
At one point, the presenter takes the number "8649" — a number which came up in the course of another calculation earlier in the show — and told people to multiply this by a random 3-digit number of their choosing. After calculating the product, they were then supposed to give him all but 1 of the digits of that product. He would then tell them the digit they had omitted. How could he manage such a trick?
In this case, notice that the first number — 8649 — is a multiple of 9. This means that no matter what number you multiply it by, you're destined to get back a number which is also a multiple of 9. Recall, however, that the sum of the digits of a number divisible by 9 is itself divisible by 9. So if the person tells you that the digits in the product — even after some random rearrangement — are "4,7,0,3,6,8," then you know the missing digit is whatever number you need to add to
(1)
in order to get a multiple of 9. In this case, you know that the missing number is 8. (Notice that if they had instead told you that the digits included "4,8,7,8,3,6" — which add up to 36 — you wouldn't have known whether the missing digit is a 0 or a 9!).
Another one of his tricks was to compute on which day of the week certain dates fell. Someone would say, for instance, "January 11 1980" and he would say "That was a Friday." To see one way he might have computed the day of the week, check out problem 2 in the "student projects" of Chapter 2. You might also rewatch that portion of the video and keep your eyes peeled on his hands — he uses them to keep track of certain calculations once people give him bits of information.
Calculating Euler's Phi
Last class period we introduced Euler's
function and saw that for any number a with the property that
, we must have
. This was a generalization of Fermat's Little Theorem. Notice that this gives us a method for computing the multiplicative inverse of a given number modulo n without a guess-and-check technique; it provides a systematic way to find the inverse.
Corollary: If
, then then the multiplicative inverse of a modulo n is
.
Last class period we also calculated
for a handful of (small) values of n. Our technique was just to write down all the numbers between 1 and n and then compute — one by one — which ones were relatively prime to n. This is an effective method, of course, but it is also pretty time consuming. We want a faster way to compute the value of
. So let's try to come up with some formulas for "special values" of n.
Lemma: If p is a prime number, then
.
Proof: We know that any integer
must be relatively prime to p because p is a prime number. Hence all
of these numbers are relatively prime to p. Since p certainly isn't relatively prime to itself, this means that there are
integers between 1 and p which are relatively prime to p. 
Lemma: If p is a prime number, then
.
Proof: Notice that any number n for which
must be a multiple of p. Hence if we can list the multiples of p which fall between 1 and
, we'll have a complete list of elements in that range which aren't relatively prime to
; this will then let us compute home many numbers are relatively prime to
by just subtracting these "bad elements" from the total number of integers between 1 and
.
So let's list the multiples of p:
(2)
We can see that there are
such elements, and so the total number of integers between 1 and
which aren't relatively prime to
is
. This leaves
elements which are relatively prime to
, and this gives us
. 
Lemma: If p and q are distinct prime numbers, then
.
Proof: We'll proceed like last time, noting that numbers which aren't relatively prime to
are either multiples of p or multiples of q. This means that the numbers which aren't relatively prime sit in the lists:

The total number of terms in both lists is clearly
, but we need to account for overlap. For this, notice that elements which are in both lists are common multiples of p and q. We already know that the least common multiple of p and q is pq, and so the only element common to both lists is qp. Hence the total number of distinct elements between the two lists is
. This means that, in total, we have

elements which are relatively prime to pq. The fact that this number is the same as
follows from our formula for
evaluated at primes. 
Refining Our Calculations
Now that we have some rules for calculating
, we can evaluate this function for lots of integers. For instance, we get
| n | ![]() |
|---|---|
| 1 | 1 |
| 2 | 1 = 2-1 |
| 3 | 2 = 3-1 |
| 4 | 2 = 42-41 |
| 5 | 4 = 5-1 |
| 6 | 2 = (2-1)(3-1) |
| 7 | 6 = 7-1 |
| 8 | 4 = 23-22 |
| 9 | 6 = 32-31 |
| 10 | 4 = (2-1)(5-1) |
| 11 | 10 = 11 - 1 |
Notice, that when we get to
, however, we no longer have a clean formula for calculating
. We can list the numbers between 1 and 12 easily enough and test for relative primality, however, and when we do so we see that
. Notice we have

but that
(6)
Similar calculations will verify that
, from which we can see that

but that
(8)
What is happening which determines which of these equations work and which don't? This behavior is explained by the following
Theorem: If n and m are relatively prime, then
.
Before we prove this theorem, though, note that it tells us that for an integer n which factors as
we get

Now we'll move on to think about the proof of the theorem. For this, we'll need the following
Lemma: Suppose that
and that a satisfies
. Then there exists unique integers
with
and
so that a is a solution to the simultaneous congruences
Moreover, we have thatif and only if
or
.
Proof: The first part of the theorem is just the Chinese Remainder Theorem, so there's nothing to prove there. For the second, we'll start by assuming that
, and we'll show that either
or
. Now let d be a common divisor of a and nm, and let p be a prime divisor of d. Then we have that p is a common divisor of both a and nm. Since
we know by Euclid's Lemma that either
or
. Hence we have either p is a common divisor of a and n or p is a common divisor of a and m.
Assume we're in the former case. Now because
there exists some
so that
. Hence we have
. Since p divides both a and n we therefore have
, and so p is a common divisor of both
and
, as desired. In the case we haven't considered — that p is a common divisor of a and m — we can use a similar argument to prove
. Hence we get the desired conclusion.
Now let's prove the opposite direction, so that we want to prove that if either
or
holds, then we have
as well. For this, assume we're in the case where
. Then we have a common divisor
of both
and
. Because
, this means that d is a common divisor of a as well. Hence we have
, from which we conclude
, as desired. In the remaining case — where
— a similar argument shows that
, from which
is easy. 
With this lemma in hand, we can go on to prove our big theorem.
Proof that
whenever 
To prove the result, the previous result says that a number a with
is represented uniquely by numbers
with
and
. Hence we ask the following question: for which choices of
can we conclude that a is relatively prime to nm? Well, we know that
if and only if both
and
. The number of choices
which satisfy
is precisely
, since
counts — by definition — the number of elements between 1 and n which are relatively prime to n. Similarly, we know that the number of choices of
so that
is given by
.
Since our choices for
and
can be made independent of each other, this means that we have a total of
choices for
which produce an integer relatively prime to nm. Hence we conclude
. 






.
.
.
.
and that a satisfies 
