To know what day of the week it will be in days there is no need to count them, because only the remainder of on division by matters, and the problem is to turn that shortcut into arithmetic that can be trusted.
The previous lesson ended by noticing that divisibility questions are really questions about remainders. This lesson makes the remainders into a number system. It uses Bézout's identity from an earlier lesson: always has an integer solution, found by running Euclid's algorithm backwards.
Congruence
Fix a positive integer , the modulus. Two integers and are congruent modulo , written
when . So , since , and , since . This is the same as leaving the same remainder: if and with , then , and lies strictly between and , so exactly when .
Proof and Logic showed that congruence modulo is an equivalence relation, so it splits the integers into classes. Write for the class of , the set of all integers congruent to it. Modulo the class is , and there are exactly five classes, , one for each possible remainder. The set of the classes is written .
A class has many names: , and are the same class modulo . That freedom lets a large number be swapped for a small one, and it is also a danger, because anything defined through a representative must come out the same whichever one is chosen.
Adding and multiplying classes
The natural definitions are and , and they are only well defined if the answer does not depend on which names were picked for the inputs.
Theorem. If and , then and .
For the sum, , a sum of two multiples of . For the product, add and subtract :
and both terms on the right are multiples of . So has an addition and a multiplication, which inherit the commutative, associative and distributive laws from the integers. Repeating the product rule gives , so any calculation built from sums and products may be reduced at any stage.
The days of the week are . A year of days is weeks and day, so and a date moves one weekday later each ordinary year, and two after a leap day. The question in the first line is now easy: , so , and days after a Sunday is a Saturday.
Example. Apollo 11 landed on the Moon on Sunday 20 July 1969. On what day of the week did the fiftieth anniversary, 20 July 2019, fall?
The fifty years contain the leap days of 1972, 1976 and so on to 2016, which is twelve of them (2000 was a leap year). So the gap is days. Modulo , replace by :
Six days after Sunday is Saturday, which a computer's calendar confirms.
Now you. The United States Declaration of Independence is dated Thursday 4 July 1776. On what day of the week does its 250th anniversary, 4 July 2026, fall? Remember that in the Gregorian calendar 1800 and 1900 were not leap years, while 2000 was.
Answer
The leap years from 1780 to 2024 number , less 1800 and 1900, so leap days. The gap is , since . Two days after Thursday is Saturday.
Divisibility tests from and
A number written in decimal with digits is . Since , every power , and the whole number is congruent to . So a number and its digit sum leave the same remainder on division by , and by too, since also . The digits of sum to , a multiple of , so divides it.
Modulo , instead, , so , and a number is congruent modulo to its alternating digit sum , starting from the units. For this is , so divides it, and indeed .
Both tests give more than a yes or no: they give the remainder. The alternating sum of is , so it leaves remainder on division by .
Inverses and zero divisors
Addition in can always be undone, since cancels . Multiplication is another matter. A class has a multiplicative inverse if some has , that is . Modulo every non-zero class has one: , and are all . Modulo only do.
Theorem. has an inverse modulo exactly when .
The congruence says for some integer , that is . So an inverse exists exactly when is an integer combination of and . If , Bézout's identity supplies the combination. If , then divides every combination and cannot divide . The proof is also the method: the from extended Euclid is the inverse. An earlier lesson found , which read modulo says , so the inverse of is . Check: .
When is composite, with , then although neither factor is , as in . A non-zero class that multiplies some non-zero class to is a zero divisor, and it has no inverse: if with not congruent to and , then . In fact, if then , so every non-zero class is either invertible or a zero divisor, never both.
This is why cancellation is unsafe: , yet and are not congruent modulo . Cancelling is multiplying by its inverse, so it is allowed exactly when . Modulo a prime every non-zero class is coprime to and so invertible: allows division by anything non-zero, like the rationals. That is Euclid's lemma from the previous lesson in new clothes: modulo a prime, a product of non-zero classes is never zero.
Solving
A linear congruence says for some integer , so it is solvable exactly when is a combination of and , which by Bézout means exactly when divides . When there is one solution class, . When and , write , , . Then exactly when , and since that has one solution modulo . Modulo it splits into the classes .
Example. Solve .
Here , which divides , so there are four solutions modulo . Dividing through gives . For the inverse of run Euclid: , , . Backwards, , so . Then , and modulo the solutions are . Check one: . By contrast has no solution, since does not divide .
Now you. Solve .
Answer
divides , so there are three solutions. Dividing by gives . Since , the inverse of is , and . Modulo : . Check: .
The Chinese remainder theorem
The Sunzi Suanjing, a Chinese arithmetic manual written between the third and fifth centuries AD, asks: there are things whose number is unknown; counted by threes, two are left; by fives, three are left; by sevens, two are left. How many things? In congruences, find with , and .
Theorem. If are pairwise coprime and , then for any the system has a solution, and it is unique modulo .
The proof builds the solution. Let , the product of the other moduli. It is coprime to , since a prime dividing both would divide some with as well as . So has an inverse modulo . Put
Modulo , every term except the th vanishes, since its contains the factor , while , so . For uniqueness, if and both work, then every divides . The share no prime, so by unique factorisation their product divides too.
Example. Solve Sunzi's problem.
. For : , whose inverse is . For : , inverse . For : , inverse . So
and . Check: . So the answer is , as the Sunzi Suanjing says, or any .
Now you. Find the smallest positive with , and .
Answer
. , inverse ; , inverse ; , inverse . Then , and . Check: .
Coprimality matters. The system , has no solution, since the first makes odd and the second even. The theorem also counts: the classes modulo and the lists of remainders correspond one to one, so a number modulo is the same information as its three remainders modulo , and .
The ISBN check digit
Ten-digit International Standard Book Numbers, standardised in 1970, end in a check digit chosen so that, with the digits weighted down to ,
The second edition of Concrete Mathematics by Graham, Knuth and Patashnik has ISBN 0-201-55802-5, and the weighted sum is . A check digit of is printed as X.
A single wrong digit is always caught. Changing the digit with weight from to changes the sum by , where and is non-zero and at most in size. Neither factor is a multiple of the prime , so by Euclid's lemma the product is not either, and the sum stops being . Swapping two adjacent digits and , with weights and , changes the sum by , again non-zero modulo when .
A composite modulus has zero divisors, and they let errors through. The thirteen-digit ISBN that replaced ISBN-10 on 1 January 2007 works modulo with weights alternating and , so swapping adjacent digits that differ by changes the sum by and goes unnoticed.
Powers repeat
Take powers of modulo : , and then, since , the list starts again. Powers of go and repeat after three steps. Every sequence of powers modulo must eventually repeat, because there are only classes, but these return to , and the lengths and both divide . The next lesson explains the pattern with Fermat's little theorem and Euler's generalisation, computes huge powers by repeated squaring, and uses the inverses found here to build RSA, a lock anyone can close and only one person can open.