Modular Arithmetic: Remainders, Congruences, and Competition Methods
A progressive guide to modular arithmetic, from remainders and congruences through powers, divisibility, systems of congruences, inverses, and advanced competition methods.
Remainders and the
Modular arithmetic focuses on what remains after division rather than on the full size of a number.
For positive integers and , write
The value is the , and the notation asks for that . For example,
The divisor is the . When dividing by , the only possible standard remainders are . A cannot be at least the , because another copy of the could still be removed.
A useful calculation routine is:
Find the largest multiple of the that does not exceed the number.
Subtract that multiple.
Check that the result lies between and one less than the .
For instance,
Special cases are worth recognizing. If , then . If , then .
and Classes
compares behavior. The statement
means that and have the same when divided by . Equivalently,
For example,
because , which is divisible by . The same fact can be checked through remainders: both numbers leave modulo .
Do not confuse a modulo result with a . The statement
identifies the actual standard , whereas
places and in the same class modulo . The numbers are all congruent modulo , because each leaves .
A reliable way to verify a is to subtract the two sides and test divisibility by the . Remember that is not ordinary equality: and are different integers even though they are congruent modulo .
Arithmetic with Congruences
Congruences can be added, subtracted, and multiplied. If
then
Reduce the final result to a standard when a numerical answer is requested.
For example, to find , reduce first:
Thus,
Subtraction may produce a negative intermediate value. For example,
The standard is , obtained by adding to . More generally, add or subtract the until the result lies in the range from through .
These rules make large expressions manageable. For
replace the numbers by , , and :
A key caution is division. Addition, subtraction, and multiplication preserve directly, but cancellation requires a and therefore a relatively prime factor.
Choosing Moduli for Divisibility and Parity
Choose a that matches the information being asked for.
Use modulo for parity: even numbers satisfy , and odd numbers satisfy .
Use modulo or modulo for digit-sum tests.
Use modulo for the last two digits.
Use modulo for the last three digits.
Use modulo for the last digit.
Use modulo for alternating digit sums.
For a decimal number, powers of simplify under these moduli. Since , a number and its digit sum have the same modulo . For example,
Parity often gives a fast contradiction. Three odd integers have sum congruent to
so their sum cannot be even.
For several conditions, translate each sentence into a . For example, “leaves when divided by ” becomes , while “is divisible by ” becomes . Then list candidates, substitute, or combine the conditions systematically.
Always check compatibility first when moduli share a factor. A number satisfying is even, while a number satisfying is odd; therefore, those two conditions cannot hold simultaneously.
Powers, Cycles, and Digit Problems
Powers often have repeating patterns. To find the last digit of a power, work modulo . The powers of have last-digit cycle
Because the cycle length is ,
so
A of when reducing an exponent by a cycle length means use the last entry of the cycle, not the first. For example, the exponent is congruent to modulo , so corresponds to the fourth cycle entry, namely .
For a large exponent, use one of three approaches:
Calculate successive powers until a cycle appears.
Use and reduce after each multiplication.
Apply a theorem such as or Euler's theorem when its conditions hold.
is efficient because an exponent can be written as a sum of powers of . For example, , so compute , , and by successive squaring, then multiply their reduced residues.
says that for a prime with ,
Thus, for , reduce the exponent modulo :
The condition is essential. Do not reduce exponents automatically without checking the relevant cycle or theorem.
Combining Conditions
A system of congruences can often be solved by listing candidates or by substitution. Consider
Numbers congruent to modulo are . The first one that is congruent to modulo is , so
The period is because and are relatively prime.
Substitution gives another method. To solve
write . Then
Since , we obtain , and therefore is the least positive solution. The complete solution is
This is an instance of the : compatible conditions with relatively prime moduli determine one residue modulo the product of the moduli. If moduli share factors, the corresponding remainders must agree modulo the common factors.
For a
let . If , there are no solutions. If , divide the entire by , solve the reduced , and then account for the resulting solution classes modulo .
Modular Inverses and Safe Division
Division in modular arithmetic means multiplication by a . An inverse of modulo is a number satisfying
Such an inverse exists exactly when . For example, because . Therefore, solving
gives
If the coefficient and are not relatively prime, cancellation may be invalid. From , it does not follow that . The original has more than one solution class.
The Euclidean algorithm can find inverses. For instance,
Working backward gives
so and are inverses of modulo . This allows the equation
to be solved as
For a prime , also gives
when . Use the Euclidean algorithm for small direct computations, and use exponentiation when powers are already part of the problem.
Advanced Competition Methods
Factorials and products often simplify through divisibility. If a factorial contains enough factors to include every prime factor of the with sufficient multiplicity, its is . For example,
contains both and , so it contains a factor of . Hence
For a prime , states
For example,
A nearby factorial can be related to . Since
and , we get
Thus, , and multiplying by the inverse of yields .
For factorial quotients, simplify the quotient as an ordinary integer before reducing whenever possible. Do not cancel factors inside a unless the canceled factor has a .
A dependable competition workflow is:
Identify the target and factor it if useful.
Inspect factorials and products for immediate divisibility.
Reduce large bases to small congruent values.
Find a cycle or use for powers.
Apply only when its conditions hold.
Replace division with multiplication by a .
Convert negative answers to standard remainders and verify the result.