Modular Arithmetic

Usually, when we divide two numbers, we are primarily interested in the quotient as the answer. But really, when two numbers are divided, there are two "parts" to the answer -- the quotient and the remainder. (Remember grade school, when you would express the answer to 11 / 3 as 3R2 ?)

In mathematics, we use two different operators to refer to the different results of a division operation. We use the familiar syntax a/b to refer to the quotient, and we use the expression a mod b to refer to the remainder of the division of a by b.

Example 1:

Since "11 divided by 3" gives a result of "3 remainder 2", we would say
          11 / 3 = 3
          11 mod 3 = 2

Example 2:

Since "20 divided by 4" results in 5, with no remainder, we would say
          20 / 4 = 5
          20 mod 4 = 0

One situation where we use mod - without even thinking about it - is when we do arithmetic with time values. For instance, if it is now 10:00 and you plan to meet your friend in 3 hours, you mean that you will be meeting at 1:00. On a traditional analog clockface, there is no way of distinguishing between AM and PM, or between days of the week. The only information displayed on the clock face is the amount of time that has elapsed since 12:00. So, the clock face is really showing the time value mod 12. It is not showing how many times the hands have travelled around the face, but it does show how much time is "left over" from the 12-hour cycles. For this reason, modular arithmetic is sometimes called clock arithmetic.

Example 3:

If the clock shows 9:00 now, what time will it be in 100 hours from now?

The answer is (9 + 100) mod 12 = 1, so the clock face will read 1:00.

Example 4:

If today is Monday, what day of the week will it be 100 days from today?

Since we are not interested in how many weeks pass in the course of 100 days, but are only interested in how many days are "left over", we are looking for the answer to 100 mod 7 = 2. That means that after 100 days, it will be 2 days later in terms of the days of the week, so 100 days from a Monday will fall out on a Wednesday.

Example 5:

If a car's odometer shows 95,000 miles now, what will it show after the car is driven another 20,000 miles?

A car's odometer has room for only 5 digits. That means that the largest number that can be displayed is 99,999. When the mileage reaches 100,000, the initial digit one is "lost", and the odometer displays 00000. So the mileage displayed on the odometer is what is "left over" when multiples of 100,000 are ignored. In this case, the answer is (95000 + 20000) mod 100000 = 15000 so 15,000 will be the value displayed on the odometer.

Go to the modular arithmetic practice page