# Modular Arithmetic

Modular Arithmetic is useful in a variety of contexts and even is a helpful way to think about positional numeral systems (like our base ten system) in which certain placeholders are used. There are many applications in computer programming and cryptography as well as systems of time and date keeping, but we will focus here only on how to compute results. We will restrict ourselves to the integers and also will not delve into details about relations, congruence, etc. Students interested in these detail are referred to the Wikipedia articles of the topics of their interest, as well as any first year undergraduate textbook on discrete math or number theory.

## The Division Algorithm

The division algorithm is the familiar procedure from a first introduction to division. When asked to find the **quotient** (the number of equal bunches of a certain size) when dividing one natural number (the **numerator** or **dividend**) by another (the **denominator** or **divisor**) we often get a leftover **remainder** (henceforth called the **residue**). For instance if we are asked to divide we have a dividend (numerator) of and divisor (denominator) of . We rewrite the problem in an equivalent manner and note that the quotient is and the residue is . In general we can write any integer (the dividend) as the product of any integer (the divisor) and some integer (the quotient) adder to an integer (the residue). The value of the residue must be between and . Where the straight bars represent to absolute value (*ie.* positive numbers remained unchanged and negative numbers are multiplied by to make them positive).

Note the word divisor is often also used as a short hand for a number that divides another with no residue (*ie.* divides with residue ). This is different to the sense in which the word is used earlier in this section.

## The Integers Modulo

Note: when congruence () comes up, feel free to treat it as equality (). There is a difference (for instance we will see how and can be congruent shortly), but it is not useful to belabour the point for our purposes.

What we mean by the **integers modulo ** is that we will represent each number by it's residue when it is divided by . So , while . , so we notice that many of our numbers will be mapped to the same place. In fact we only have numbers left. They are the numbers in the set , the integers modulo . In the case of integers modulo we have numbers . Note while the notation is common, it is not the only notation and is the same notation used for the n-adic integers, so use it with some care.

We will define addition subtraction and multiplication on as taking elements of and doing addition, subtraction or multiplication on them as normal, then asking what the result is equal to modulo . We can take the mod after each step (to keep the numbers being crunched small) or we can just do all the computation at once and do one mod at the end (quicker if being done with a calculator). The results will be the same. Note negative answers, must give a positive residue by definition. For example so

For example and , and as expected.

## Exercises

Try some computations and see if you get the same answer both ways. First do the computation by hand taking the mod at each step, then check by doing all the computations on a calculator and taking the mod at then end. To do the mod quickly on a calculator you can divide by , take the answer and subtract what the answer rounded down is (*ie.* -6.2-(-7)=0.8) then multiply by . You will get the number you calculated or something close, depending on the accuracy of the device you are using.

For example as , , and