- Learn
- Mathematics
- University Math
- Discrete Mathematics
- Divisibility and Modular Arithmetic
Divisibility and Modular Arithmetic
BeginnerLesson 5 of 10 in Discrete Mathematics Course
What you will learn
- Use the definition of divisibility to test and prove divisibility statements, and divide any integer by a positive integer to get a unique quotient and remainder.
- Use the definition of divisibility in calculations and proofsDecide whether one integer divides another, use the basic properties of divisibility, and prove divisibility statements directly from the definition.
- Divide with remainder using the division algorithmState the division algorithm, find quotients and remainders for positive and negative integers, and use remainders to sort integers into cases.
- Use the definition of divisibility in calculations and proofs
- Read and write congruences, compute sums, products and powers modulo , and apply modular arithmetic to divisibility tests, check digits and other cyclic problems.
- Understand congruence modulo m and congruence classesDefine congruence modulo a positive integer, move between its equivalent forms, and describe the congruence classes that make up the integers modulo m.
- Add, multiply and raise to powers modulo mUse the rules that let congruences be added, multiplied and raised to powers, reduce early to keep numbers small, and avoid the operations that do not carry over to congruences.
- Apply modular arithmetic to tests, codes and cyclesExplain divisibility tests, check digits, hashing and simple pseudorandom generators with congruences, and compute with them.
- Understand congruence modulo m and congruence classes
- Write integers in any base b greater than 1, convert between bases, and use binary expansions to compute large powers modulo m efficiently.
- Convert integers between base 10 and any base bExplain base-b expansions, convert from base b to decimal by place values or nested multiplication, and convert from decimal to base b by repeated division.
- Work with binary, octal and hexadecimal, and compute powers modulo mConvert between binary, octal and hexadecimal by grouping digits, add numbers in a base b, and use the binary expansion of an exponent to compute modular powers by repeated squaring.
- Convert integers between base 10 and any base b
- Recognize and test primes, explain why there are infinitely many, and use the unique prime factorization of integers to answer questions about divisors.
- Recognize primes and test whether a number is primeDefine primes and composites, test primality by trial division up to the square root, list primes with the sieve of Eratosthenes, and prove that there are infinitely many primes.
- Factor integers into primes and use the factorizationState the fundamental theorem of arithmetic, find prime factorizations, and use them to describe and count divisors and to recognize squares.
- Recognize primes and test whether a number is prime
- Compute greatest common divisors and least common multiples, run the Euclidean algorithm and its extended form, and use Bézout's identity to prove Euclid's lemma and solve linear equations in integers.
- Compute gcd and lcm, including with the Euclidean algorithmDefine the greatest common divisor and least common multiple, compute them from factorizations, and run and justify the Euclidean algorithm.
- Find Bézout coefficients with the extended Euclidean algorithmState Bézout's identity, find integers s and t with gcd(a, b) = sa + tb by back substitution or by a running table, and check and vary the coefficients.
- Use Bézout's identity to prove Euclid's lemma and solve equations in integersDerive Euclid's lemma and the uniqueness of prime factorization from Bézout's identity, and decide whether ax + by = c has integer solutions and find them all.
- Compute gcd and lcm, including with the Euclidean algorithm
- Decide when an integer has an inverse modulo m, find it with the extended Euclidean algorithm, and solve congruences of the form ax ≡ b (mod m).
- Find inverses modulo mDefine a modular inverse, decide whether one exists from the gcd, and find it by inspection for small moduli and by the extended Euclidean algorithm in general.
- Solve linear congruencesSolve ax ≡ b (mod m) with an inverse when gcd(a, m) = 1, decide solvability and count solutions when gcd(a, m) > 1, and state and check the full solution set.
- Find inverses modulo m
Divisibility and Modular Arithmetic study guide
1Reason about divisibility, quotients and remainders
Exact division and division with remainder organize integer calculations. You will learn to read divisibility statements, prove them by exposing integer factors, and count multiples. Then you will use the unique quotient and nonnegative remainder to handle negative dividends, split proofs into complete cases, and track positions in repeating cycles. The definitions matter: a valid division equation must satisfy the remainder bounds as well as the arithmetic.
1.1 Use the definition of divisibility in calculations and proofs
Divisibility asks whether one integer is an exact integer multiple of another. It also gives a useful way to prove statements: show that an expression has the required integer factor.
Read a divisibility statement
For integers and , the statement means that for some integer . Read it as “a divides b.” The integer is a divisor or factor of ; is a multiple of . Thus because , while because is not an integer.
The order matters: is true, but is false. The symbol names a relation, not a calculation. Write to give a quotient; writing mixes a statement with a number.
Signs and zero follow the same definition. Every nonzero integer divides zero, since . Also divides every integer and every nonzero integer divides itself. Negative divisors work: proves . The positive divisors of are .
Turn the definition into a proof
Suppose and . Write and for integers . Then
Because is an integer, . The same calculation with integer weights gives . A common divisor therefore divides every integer linear combination of the two numbers, including their difference.
Two other useful rules follow by factoring. If , then , so for every integer . If also , then ; this proves transitivity, and imply .
These implications cannot simply be reversed. For instance, even though neither summand is divisible by . Also , although divides neither factor. A prime divisor has a stronger product rule, proved using Bézout's identity later.
Prove a claim about every odd integer
Let be odd, so for an integer . Expand and factor:
One of the consecutive integers is even. Their product is therefore for an integer , giving . This proves for every odd integer. Checking gives , but that check alone would establish only one case.
Count multiples up to a bound
For positive integers , the positive multiples of up to are , where is the largest integer with . Their number is . Up to there are positive multiples of , ending at . Zero is excluded because the count is of positive integers.
Key Takeaways
- means for an integer .
- A common divisor divides every integer linear combination.
- Divisibility is transitive and is preserved when the dividend is multiplied by an integer.
- A divisor of a sum or product need not divide its individual terms or factors.
- There are positive multiples of up to .
1.2 Divide with remainder using the division algorithm
Division with remainder gives every integer a fixed place between two consecutive multiples of a positive divisor. That place remains well defined when the integer is negative.
Find the quotient and remainder
The division algorithm states that for every integer and positive integer there are unique integers such that
Here is the dividend, the divisor, the quotient, and the remainder. Despite its name, the division algorithm is an existence-and-uniqueness theorem. The notation means and means .
Calculate , then . For divided by , the equation gives quotient and remainder . Exact divisibility is the special case : exactly when .
For divided by , the floor of is . Hence , with remainder . The equation is true, but its negative final term is not a valid mathematical remainder.
Separate mathematical mod from code
With positive divisor , Python's expression -11 % 3 gives 1. C and Java use integer division truncated toward zero, so their matching % result is -2. JavaScript's % also uses a truncated quotient and returns -2; its / operation itself does not truncate. When translating a modular calculation into code, the operator's negative-input rule matters.
Why the result exists and is unique
Consider all nonnegative integers of the form . Some exist: taking sufficiently negative makes the expression nonnegative. The well-ordering principle gives a smallest such value, . If , then would be a smaller nonnegative value of the same form. Thus .
For uniqueness, suppose with both remainders between and . Then , but . Zero is the sole multiple of in that interval. The remainders are equal, and so are the quotients.
Use all possible remainders as cases
The three forms partition the integers. This proves that . In the first case is divisible by . In the second, ; in the third, . Each case supplies a divisible factor, so the whole product is divisible by .
Remainders also locate positions in cycles. Starting at 09:00, another 100 hours leads to , or 13:00. For days of the week, : 100 days after a Wednesday is a Friday. The quotient counts complete cycles; the remainder gives the movement within a cycle.
Key Takeaways
- The division equation must satisfy , including for negative dividends.
- Use and .
- Programming remainder operators can use different conventions for negative inputs.
- Remainders give exhaustive cases and positions within repeating cycles.
2Calculate and reason with congruences
Congruence keeps track of what integers share when multiples of a fixed modulus are ignored. You will move between differences, remainders, and classes, then calculate with smaller representatives. The same rules explain decimal divisibility tests, check digits, storage slots, and repeatable number generators. Addition and multiplication work smoothly; cancellation needs a gcd check, and large exponents need a justified cycle or a separate efficient method.
2.1 Understand congruence modulo m and congruence classes
Two integers can differ while occupying the same position in a repeating cycle. Congruence makes that idea precise and lets us calculate with whole classes of integers.
Test whether two integers are congruent
For a positive modulus , define to mean . Equivalent tests are that for some integer , or that and have the same least nonnegative remainder modulo .
For example, because their difference is , a multiple of . Each has remainder . In contrast, , since their difference is not divisible by .
A congruence compares two integers; the operation returns one integer in . Thus is true, but is false. The remainder is . A number on the right of a congruence need not be the least nonnegative representative.
Negative representatives are useful. The congruence holds because the difference is . Writing can make a power calculation much shorter.
Group integers into classes
The congruence class of modulo is
For example, . The integers and name the same class. There are exactly classes modulo , corresponding to the possible remainders. Every integer belongs to exactly one class.
Congruence is an equivalence relation. It is reflexive because , symmetric because changing the sign of a multiple leaves a multiple, and transitive because
If the first two differences are multiples of , so is the third. These properties explain why the classes form a partition: two classes are either identical or disjoint.
Calculate in the integers modulo m
The notation uses the representatives with addition and multiplication followed by reduction. In ,
Both operations stay inside the set. They are commutative and associative, and multiplication distributes over addition. The identities are for addition and for multiplication. Every representative has additive inverse ; for example, .
These operations do not depend on which representative of a class was chosen. Replacing by in the preceding product gives , which still has remainder modulo .
Modulo , the two classes are the even integers and the odd integers. Modulo , every pair of integers is congruent, because every difference is divisible by . There is just one class in that case.
Key Takeaways
- means .
- Congruent integers have the same remainder, even when one is negative.
- Congruence is reflexive, symmetric, and transitive.
- There are exactly congruence classes modulo .
- Operations in reduce sums and products to their representatives.
- Every class has an additive inverse.
2.2 Add, multiply and raise to powers modulo m
Congruences let us replace large integers with smaller representatives before calculating. Addition, subtraction, multiplication, and nonnegative integer powers respect that replacement.
Reduce before and during arithmetic
If and , then , , and . Also for nonnegative integer powers, wherever the expression is defined.
To see the product rule, write and . Expanding gives . Its difference from is a multiple of . This justifies reducing each factor, and reducing again after every product.
For example, and . Their product is therefore congruent to . The full product has the same remainder, but computing it is unnecessary.
Shorten powers using a demonstrated cycle
The powers of modulo are , then repeat. Since and ,
The last decimal digit is . The exponent is reduced using the cycle length . Reducing an exponent modulo the original modulus is not a general rule. For instance, , while .
Check a common factor before canceling
Division can lose information. Modulo , , but . The factor has hidden the difference between the two classes.
For , let . Cancellation gives . The original modulus survives precisely when . To justify the smaller modulus, write and . Then and , so the coprime divisibility rule gives .
A composite modulus also permits zero divisors: nonzero classes whose product is zero. For instance, although neither factor is congruent to zero. With a prime modulus , Euclid's lemma gives only when divides a factor, so this cannot happen.
Rule out an integer representation
Every integer is congruent to or modulo . Squaring those representatives gives . A sum of two squares can therefore have only residues modulo . Since , it cannot be a sum of two integer squares. A residue obstruction can rule a representation out without searching through possible integers.
Key Takeaways
- Reduce terms and factors early; reduce the final result again.
- Shorten an exponent only through a justified cycle.
- Cancel a factor without changing the modulus only when it is coprime to that modulus.
- A composite modulus can have nonzero zero divisors.
- Squares modulo have residues or .
2.3 Apply modular arithmetic to tests, codes and cycles
Modular arithmetic turns long numbers into small checks and repeatable rules. The useful modulus depends on what information the application needs to retain.
Derive decimal divisibility tests
Because , every decimal place value is congruent to . A number is therefore congruent to its digit sum modulo , and also modulo . For the sum is , giving remainder modulo . The number is divisible by neither nor .
For , use . Successive place values alternate between and . Starting at the units digit gives , so is divisible by . The last two digits decide divisibility by because ; the last digit decides divisibility by and .
Choose and check a check digit
A check digit makes a weighted digit sum satisfy a congruence. An ISBN-13 uses weights from the left and requires the complete sum to be modulo . For the first twelve digits “978012345678,” the weighted sum is
The check digit must satisfy , giving . The resulting checksum example is “9780123456786.”
A single changed digit alters the sum by its nonzero change times or . Both weights are coprime to , so every single-digit error is detected. Swapping neighboring digits changes the sum by . Distinct digits differing by can be swapped without changing the checksum. Passing a checksum does not show that the digits were entered without error.
IBAN uses a different rule: move the first four characters to the end, replace letters with through , and test for remainder modulo . This checks the checksum, not whether an account exists. For a long converted integer, keep a running remainder. If a prefix has remainder , appending a digit gives new remainder . For example, processing “1234” gives successive remainders .
Assign keys to slots
The hash function assigns keys to slots. With , maps to slot . Adding gives , which maps to the same slot. Such a collision requires a handling rule, such as checking subsequent free slots; the remainder alone cannot distinguish the keys.
Generate a repeatable sequence
A linear congruential generator uses . With , its states are . Once a state repeats, the deterministic rule repeats everything that follows. The period here is ; a generator with possible states cannot have a repeating cycle longer than . The seed fixes the sequence, which is why it is called pseudorandom.
Key Takeaways
- Decimal place values explain digit-sum and alternating-sum tests.
- ISBN-13 uses alternating weights and total remainder zero modulo .
- An ISBN checksum detects every single-digit change but misses some neighboring swaps.
- IBAN checksum testing uses remainder modulo after rearrangement and letter conversion.
- Keys congruent modulo the slot count collide under remainder hashing.
- A repeated generator state starts the same subsequent sequence.
- Appending a digit updates a running remainder by .
3Represent and compute with integers in other bases
A base changes how an integer is written, not its value. Place values explain how to read unfamiliar numerals, and repeated division builds their digits in reverse order. Binary, octal, and hexadecimal connect through groups of bits. You will also add with carries in the chosen base and use the binary digits of an exponent to select powers in a repeated-squaring calculation, keeping each modular result small.
3.1 Convert integers between base 10 and any base b
A numeral records an integer through place values. Changing the base changes the allowed digits and place values, while the integer itself stays the same.
Read a base-b expansion
For an integer base , each digit has a value from through . A positive integer has a unique expansion
with nonzero leading digit . The subscript in identifies the base. Binary uses base , octal base , and hexadecimal base . Hexadecimal digits represent values . The numeral is invalid because is not an octal digit.
To convert to decimal, multiply each digit by its place value and add. For example,
Similarly, . A zero digit contributes nothing but still reserves a place; removing an internal zero changes which powers multiply the other digits.
Horner's method evaluates the same expansion from the left. Start with the leading digit, multiply by the base, and add the next digit. For , first , then . This avoids listing every place value.
Build the digits by repeated division
The division algorithm gives with . Therefore is the units digit, and contains all the digits still to find. Repeat with the quotient until it becomes zero.
For in base :
The remainders appear as units, sevens, then forty-nines. Read them from the last line upward to obtain . Check the result by expansion: . Its binary expansion is .
Reading the remainders in their discovery order gives , which is a different integer. The division equation explains the order: the first remainder is multiplied by , the next by , and so on.
Convert between unfamiliar bases
A dependable route is to evaluate the original numeral in decimal, then divide repeatedly by the target base. For instance,
Dividing by gives , , and . Hence .
Count digits without converting
A positive integer has digits in base exactly when . The lower bound is the smallest numeral with that many digits; the upper bound is the first with another digit. Since , the binary expansion of has digits. An exact power sits at the lower end of a new digit length.
Key Takeaways
- Every digit value must be smaller than the base.
- Convert to decimal by place values or repeated multiply-and-add.
- Convert from decimal by division, reading remainders last to first.
- A positive integer has base- digits when .
3.2 Work with binary, octal and hexadecimal, and compute powers modulo m
Some base changes need no decimal calculation. Binary also provides an efficient plan for computing a large modular power: each exponent bit selects a power built by squaring.
Group binary digits from the right
Since , one octal digit holds exactly three binary places. Since , one hexadecimal digit holds four. Group binary digits from the right and add leading zeros to complete the leftmost group.
For , hexadecimal grouping gives . The groups have values , so the result is . Octal grouping gives , or . Each numeral represents .
The right-hand end fixes the units place. Grouping from the left and filling the rightmost group with zeros would multiply the integer by a power of two. Leading padding zeros are safe; trailing padding zeros are not.
For the reverse conversion, replace every octal digit by three bits or every hexadecimal digit by four bits. Keep internal zeros: becomes . Only leading zeros can then be dropped without changing the value.
Carry in the base being used
Add from the units column. For a column total , write digit and carry . In binary a total of is written as digit with carry ; a total of gives digit with carry .
For , align as and . From the right, the column totals including carries are . The written digits are , with a final leading carry . The sum is , agreeing with . A carry moves one place left, where its value is multiplied by the base.
Use the exponent's binary expansion
To calculate , repeatedly square and reduce to get the residues of . Write as a sum of powers of two, then multiply only the corresponding residues. Reduction after each product keeps the numbers small.
For , the exponent is . The successive squares give
Select powers ; the zero bit at power means that factor is omitted. Thus . Reduce , then . The remainder is .
The binary expansion controls which factors to multiply; it does not replace the exponent by its remainder modulo . The method needs about squarings and at most that many extra products. Its work grows with the number of exponent digits, instead of requiring multiplications by .
Key Takeaways
- Use groups of three binary digits for octal and four for hexadecimal.
- Group from the right and preserve internal zeros.
- In base , the column digit is and the carry is .
- Repeated squaring builds powers with exponents .
- The exponent’s 1-bits select the factors; reduce after every product.
4Identify primes and factor integers into primes
Prime numbers provide the factors from which every integer greater than one is built. You will test individual integers using a square-root bound, list primes with a sieve, and follow the proof that no finite list can contain them all. Unique prime factorization then turns questions about divisors and squares into questions about exponents. The proofs distinguish finding a factor from knowing that a whole number is prime.
4.1 Recognize primes and test whether a number is prime
A prime is an integer greater than one whose only positive divisors are one and itself. Primes are the building blocks of integer multiplication, and a small divisor search can certify a modest-sized integer as prime.
Test only the necessary divisors
An integer greater than one is composite if it has a factorization with . The integer is neither prime nor composite. Among even integers, alone is prime: every larger even integer has the proper divisor .
If is composite and , then . Thus . Some prime divisor of is no larger, so every composite integer has a prime divisor at most its square root. To test , try all primes up to and including .
For , the bound is about . The candidates are , and shows it is composite. None of those candidates divides , so is prime. Include the endpoint when it is an integer: omitting for would miss .
Trying composite divisors adds no information once their prime factors have been tested. Testing all integers up to also works, but does much more work than necessary.
List many primes with a sieve
The sieve of Eratosthenes starts with the integers through a chosen bound . Keep the smallest uncrossed integer and cross out its multiples starting at . Smaller multiples have already been removed using smaller prime divisors. Continue while .
For , sieve with . The survivors are : fifteen primes. No further sieving prime is needed because . A single primality test and a sieve share the square-root bound, but the sieve finds an entire list at once.
Prove the primes never end
Suppose a finite list contained every prime. Form . Because , it has a prime factor. Yet each listed prime leaves remainder when dividing . That factor is outside the supposedly complete list, a contradiction.
The argument does not require itself to be prime. In fact, . Both prime factors are absent from the starting list. The proof obtains a new prime factor, not a formula that always produces a prime number.
Describe how common primes are
There are primes below and below . The prime number theorem states that the count of primes up to , written , satisfies as . It describes the long-term scale of the count. It is not an exact counting formula and does not decide whether a particular integer is prime.
Key Takeaways
- A prime has exactly two positive divisors; has only one.
- Trial division must test every prime at most , including the endpoint.
- The sieve crosses out multiples starting at .
- Euclid’s proof produces a prime factor missing from any proposed finite list.
- describes an asymptotic count, not an exact formula.
4.2 Factor integers into primes and use the factorization
Prime factorization turns a number into independent choices of prime exponents. Those exponents reveal its divisors and whether it is a perfect square.
Finish the factorization
The fundamental theorem of arithmetic says that every integer greater than one is a product of primes, uniquely apart from their order. Standard form lists distinct primes in increasing order and records repeated occurrences as exponents. For example, .
Divide repeatedly by the smallest prime that still divides the remaining quotient. For , divide by , then twice by :
Since , the final factorization is . Another example is . A product such as is a factorization of , but it is incomplete as a prime factorization because both factors are composite.
When no tested prime divides the remaining quotient and the next prime exceeds its square root, that quotient is prime. Recalculate the bound for the remaining number; it can be much smaller than the original input.
Understand existence and uniqueness
Strong induction proves existence. A prime is already a prime product. If is composite, write with both factors strictly between and . The induction hypothesis supplies prime products for both smaller factors, and multiplying them gives one for .
Uniqueness uses Euclid's lemma: a prime dividing a product must divide a factor. A prime from one proposed factorization must therefore equal a prime in the other; cancel it and repeat. Including among primes would destroy this uniqueness, since any number of extra factors equal to could be inserted.
Describe and count the divisors
If , a positive divisor has the form with . No new prime can appear, and no exponent can exceed the corresponding exponent in .
For , the exponent of has four choices, the exponent of has three, and the exponent of has two. These choices are independent, so the number of positive divisors is . Counting only the distinct prime factors would give three, which omits composite divisors and .
Recognize squares and compare factorizations
Squaring a prime product doubles every exponent. Conversely, if every exponent is even, halving them gives an integer square root. Thus is a square, while is not because some exponents are odd.
For two positive integers, taking each prime's smaller exponent gives the gcd; taking its larger exponent gives the lcm. These are useful consequences when factorizations are known. Finding factorizations of large integers can be difficult, so a gcd calculation usually uses the Euclidean algorithm instead.
Key Takeaways
- Prime factorization exists and is unique up to factor order.
- Complete factorization requires every remaining factor to be prime.
- A divisor selects each exponent from zero through the exponent in the original integer.
- The divisor count is .
- A positive integer is a square exactly when every prime exponent is even.
- Minimum exponents give the gcd; maximum exponents give the lcm.
5Find greatest common divisors and express them with Bézout's identity
A gcd calculation can reveal both shared factors and integer relationships between two numbers. You will compare gcd and lcm, run Euclid’s shrinking remainder sequence, and track the coefficients that express its answer using the original inputs. Bézout’s identity then explains a prime-divisor rule and determines which linear equations have integer solutions. Finding one solution is the starting point for describing the full family.
5.1 Compute gcd and lcm, including with the Euclidean algorithm
The greatest common divisor measures the shared integer factors of two numbers. The Euclidean algorithm finds it using division with remainder, without requiring prime factorization.
Compare shared divisors and shared multiples
For integers not both zero, is their largest common divisor and is positive. For positive inputs, is their smallest positive common multiple. Also for nonzero .
Two integers are relatively prime, or coprime, when their gcd is . They need not be prime: and are coprime. A collection is pairwise coprime when every pair is coprime. The integers have overall gcd , but fail the pairwise test: and share . In contrast, are pairwise coprime.
Known prime factorizations give another method. From and , select the smaller exponents for and the larger for . A missing prime has exponent zero. For positive inputs,
Thus a known gcd gives the lcm by dividing the product by the gcd.
Preserve the gcd while shrinking the inputs
If , then . Any common divisor of divides . Conversely, a common divisor of divides . The two pairs have exactly the same common divisors.
The Euclidean algorithm repeatedly replaces by . Each nonzero remainder is smaller than the preceding divisor, so the process ends. Its last nonzero remainder is the gcd; the terminating zero is not the answer.
For and :
Following the preserved gcds gives . The final nonzero number divides both original inputs: and .
Starting with the smaller input is harmless. If , the first quotient is zero and the pair becomes . Negative inputs can be replaced with their absolute values because the positive common divisors stay the same.
Estimate the work
Lamé's theorem bounds the number of divisions by five times the number of decimal digits in the smaller positive input, with the larger input placed first. Consecutive Fibonacci numbers make the remainders decrease slowly and give the worst cases for a given input size. For there are nine divisions, including the final exact division, within the bound . The cost grows with digit length, making Euclid practical even when factoring the inputs is hard.
Key Takeaways
- Coprime integers have gcd ; pairwise coprimality checks every pair.
- gives .
- The last nonzero remainder is the gcd.
- For positive inputs, .
- Lamé’s bound is five times the smaller input’s decimal digit count.
5.2 Find Bézout coefficients with the extended Euclidean algorithm
Euclid's remainders can do more than identify a gcd. Tracking how each remainder comes from the original inputs produces an equation expressing that gcd as their integer linear combination.
State Bézout's identity
For integers not both zero, there are integers such that
The integers are Bézout coefficients. Every integer linear combination of is a multiple of their gcd, and every multiple of the gcd is such a combination. In particular, the gcd is the smallest positive value obtainable. Coprimality is equivalent to the existence of integers satisfying .
Back-substitute through Euclid's equations
For , the useful remainder equations are
Start at the last nonzero remainder and replace earlier remainders one at a time:
Now replace :
Thus . Check numerically: . Keep the original inputs visible while collecting coefficients; multiplying out every intermediate value would hide the information the calculation is meant to recover.
Distribute minus signs across whole parentheses. In the first substitution, contributes , which combines with the original to give .
Track coefficients forward in a table
An alternative keeps an invariant for each remainder: . Begin with and . Whenever the remainder update is , update both coefficients with the same subtraction:
For the same example, the rows are , , , , and . The last nonzero row contains the desired coefficients. The invariant explains why this method and back substitution agree, even though they organize the work differently.
Recognize other valid coefficients
The coefficients need not both be positive and are not unique. If and , then for every integer ,
The added terms cancel. Here and , so another pair is . Directly, . A different pair can be correct; the decisive test is its identity with the original inputs.
Key Takeaways
- Bézout’s identity expresses the gcd as with integer coefficients.
- The integer linear combinations are exactly the multiples of the gcd.
- Back substitution replaces remainders while retaining the original inputs.
- The forward method applies each remainder update to both coefficient columns.
- Check signs by evaluating the final combination.
- Bézout coefficients are not unique.
5.3 Use Bézout's identity to prove Euclid's lemma and solve equations in integers
Bézout's identity links a gcd calculation to proofs about prime factors and to equations whose unknowns must be integers. In each use, the key is that integer linear combinations are exactly the multiples of the gcd.
Prove a coprime divisibility rule
Suppose and . Choose integers with and multiply by :
The integer divides directly, and divides because it divides . It therefore divides their sum . The coprime condition is essential: but .
For a prime dividing , either already or . In the second case the rule forces . This is Euclid's lemma. Repeating the argument extends it to a product of any finite number of factors. Composite divisors do not have this property: , but neither factor is divisible by .
Justify uniqueness of prime factorization
Suppose two products of primes are equal. A prime from the first product divides the second product, so Euclid's lemma makes it divide one of the second product's prime factors. Dividing a prime forces it to be that same prime. Cancel the matching factors and repeat. Each prime occurs equally often on both sides, leaving only order as a possible difference.
Decide whether an integer equation is solvable
A linear Diophantine equation requires integer values of . For coefficients not both zero, set . Every left-hand side is divisible by , so a solution requires . Conversely, if , multiplying a Bézout identity by constructs a solution. Thus the condition is both necessary and sufficient.
For , the gcd is and , so there is no integer solution. Solving the same equation over real numbers would be a different problem.
Find and describe every solution
For , use . Multiplying by gives . From any particular solution, all integer solutions are
Here , so . Taking produces , and .
To see why no solutions are missed, subtract a particular solution from any other one. The equation becomes . Divide by . The remaining coefficients are coprime, so divides . Writing that difference as forces the stated change in .
When , the divisions by matter. For , one solution is and all solutions are . Using steps of and would retain only every third member of this family.
Key Takeaways
- If and , then .
- Euclid’s lemma requires a prime divisor.
- Euclid’s lemma proves uniqueness of prime factorization by matching and canceling primes.
- has integer solutions exactly when .
- Scale a Bézout identity to obtain a particular solution.
- All solutions use increments in and in .
6Find modular inverses and solve linear congruences
An inverse modulo a number makes some congruences as easy to solve as ordinary linear equations. You will first decide whether the coefficient is invertible and find its inverse with Bézout’s identity. When it is not invertible, the gcd still decides whether solutions exist and how many classes to report. Worked calculations connect the reduced modulus to every solution in the original modulus, including the case where every integer works.
6.1 Find inverses modulo m
A modular inverse supplies the multiplication needed to undo a coefficient in a congruence. Whether it exists depends on a gcd, and Euclid's algorithm can find it.
Define the inverse and test existence
For , an inverse of modulo is an integer with . For instance, , so is an inverse of modulo . It is an integer residue, not the ordinary fraction .
An inverse exists exactly when . If that gcd is one, Bézout's identity gives . Reducing modulo leaves , making an inverse.
Conversely, an inverse would give for an integer . Every common divisor of divides the left side and therefore divides . Thus their gcd must be one. This proves both directions of the existence test.
For modulo , the gcd is , so no inverse exists. Every product of with an integer is even and its remainder modulo cannot be . A failed search here reflects impossibility, not the need to try a larger multiplier.
Find an inverse by inspection or Euclid
For small moduli, test products until a remainder of one appears. For larger inputs, run the extended Euclidean algorithm and take the coefficient attached to , not the coefficient attached to the modulus.
To invert modulo , use
Starting with and substituting upward gives
The inverse is . Verify . This multiplication checks the coefficient and its sign independently of the substitutions.
Choose a representative
If Euclid gives a negative coefficient, reduce it modulo . A coefficient of modulo represents , since . More generally, add enough multiples of the modulus to reach the desired representative between and .
Inverses are unique modulo . If both invert , multiply by . Because , the left side becomes , giving . There are infinitely many integer representatives but just one inverse class.
Use a prime modulus
When is prime, every integer not divisible by is coprime to and therefore invertible. In , the inverses of are . The pairs and invert each other, while and each invert themselves. With a composite modulus, only the coprime classes have inverses.
Key Takeaways
- An inverse satisfies .
- It exists exactly when .
- The Bézout coefficient of gives its inverse modulo .
- Reduce negative coefficients and verify the product.
- The inverse class is unique.
- Every nonzero class modulo a prime has an inverse.
6.2 Solve linear congruences
Solving a linear congruence means finding every integer that makes it true. A gcd tells us whether solutions exist; an inverse then finds them in a suitable modulus.
Solve when the coefficient is invertible
For with , multiply by an inverse of . This gives , one solution class.
For , the inverse of is , so . Check . The answer describes all integers , including ; reporting only would omit the rest.
A larger example is . Using inverse gives . Check .
Model repeated movement
A twelve-position dial starts at and advances five positions per tick. To land on , the tick count satisfies . Since , multiply by to get . The nonnegative tick counts are . The congruence captures the entire repeating schedule.
Handle a noninvertible coefficient
Let . The congruence has a solution exactly when , and a solvable congruence has exactly distinct solution classes modulo .
If , stop: there is no solution. If and , divide the coefficient, right-hand side, and modulus by :
The reduced coefficient is coprime to the reduced modulus, so an inverse now applies. If its answer is , the representatives modulo the original modulus are .
For , divides . Reduce to . The inverse of is , so . Modulo , this gives or . Both check: and leave remainder . Keeping modulus after division would lose the class . By contrast, has no solution because .
Include the all-integers case
If , the coefficient is a multiple of the modulus. The congruence reduces to . Every integer solves it when ; otherwise none does. Thus has all ten classes modulo , while has none.
The gcd test also follows by rewriting the original statement as for some integer . This is a linear Diophantine equation, whose solvability condition is the same divisibility test.
Key Takeaways
- For a coprime coefficient, multiply both sides by its modular inverse.
- For , solvability is equivalent to .
- A solvable congruence has classes modulo .
- Divide the coefficient, right-hand side, and modulus together.
- Lift a reduced solution by steps of to list all original classes.
- If , either every integer solves the congruence or none does.
- State a class or complete list of classes and check in the original congruence.
Divisibility and Modular Arithmetic examples
1Prove divisibility and place remainders
11 steps
- 1IntroductionGive integer claims a precise meaning
When an integer is divided, two questions arise: does it divide exactly, and what remains if it does not? We will first express exact division as an integer product, then use a bounded remainder. These definitions support proofs about infinitely many integers and calculations about repeating cycles.
- 2ExplanationExpose the integer multiplier
The statement means for an integer , with . For example, because . The statement has a truth value; the quotient is a number. Keeping the divisor first in the relation helps distinguish the factor from its multiple.
- 3ExampleProve a common divisor divides a difference
Suppose and . Write and with integer multipliers. Then . Since is an integer, this is exactly the form required to prove . The proof works for every permitted input, including negative values; it does not depend on a numerical example.
- 4ChallengeTest a reversed implication
If , must divide and separately? Find a counterexample if the claim fails.
---reveal---
Take . Their sum is divisible by , but neither summand is. The common-divisor rule runs from divisibility of both summands to divisibility of their sum; the converse is false.
- 5Key InsightFactor an expression before deciding
For odd , expanding gives . Consecutive integers include an even one, so for some integer . Hence . Factoring makes the integer multiplier visible and proves divisibility by for every odd , not just for tested examples.
- 6ExplanationKeep the remainder inside its bounds
The division algorithm writes with and , uniquely. The quotient is , and the remainder is . For divided by , use . Both the equation and the bounds are required; changing the quotient forces a corresponding change in the remainder.
- 7ExampleDivide a negative integer
For divided by , the floor quotient is . This gives , so the remainder is . The tempting equation has the correct total but a negative final term. Mathematical mod uses the first representation because its remainder lies in the required range .
- 8ChallengeRecover the unique pair
Find the quotient and remainder of divided by .
---reveal---
Use . Thus , and . Choosing quotient would force remainder , outside the interval. A quick check of both the equation and the bounds detects this negative-input error.
- 9ConnectionRemainders turn a clock into arithmetic
A 24-hour clock keeps the remainder after division by . Starting at 18:00 and advancing 55 hours gives , so the displayed time is 01:00. The complete groups of disappear from the display while the leftover hour remains. The same reasoning works with seven-day cycles.
- 10ChallengeConnect a residue case to a proof
Why is divisible by for every integer ?
---reveal---
The possible remainders of are . They make , respectively, multiples of . In each case one factor is divisible by , so the product is too. Division with remainder supplies the complete case list; the divisibility product rule finishes each case.
- 11RecapChoose the definition that fits the task
To prove exact divisibility, produce an integer multiplier, often by factoring or forming a linear combination. To divide with remainder, verify the equation and , especially for negative dividends. When proving a statement through cases, check every possible remainder. For cyclic positions, discard complete cycles and keep the final remainder.
2Calculate in classes and build arithmetic checks
14 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionKeep the information a modulus retains
- 2ExplanationCompare a difference with the modulus
- 3ExampleName an entire class
- 4ChallengeSeparate a remainder from a congruence
- 5ExampleReduce the factors before multiplying
- 6ExplanationUse the period of powers
- 7ChallengeDecide what cancellation preserves
- 8Key InsightA nonzero product can become zero
- 9ExplanationLet decimal place values give the test
- 10ExampleChoose the missing checksum digit
- 11ChallengeDecide whether a swap is detectable
- 12ConnectionUse remainders as states or slots
- 13ChallengeCombine arithmetic with the meaning of a checksum
- 14RecapMatch the rule to the information needed
3Read other bases and compute modular powers
12 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionUse place values as the common thread
- 2ExplanationRead digits with their place values
- 3ExampleBuild a numeral from the units upward
- 4ChallengeConvert in both directions
- 5ExplanationGroup by powers of two
- 6ExampleCarry in binary columns
- 7ChallengeKeep zero groups intact
- 8ExplanationPlan a large power with the exponent bits
- 9ExampleSquare and reduce one line at a time
- 10ExampleMultiply only the selected powers
- 11ChallengeConnect base conversion to power selection
- 12RecapCheck value, position, and selected factors
4Test primes and count divisors
10 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionSeparate a prime test from a factorization
- 2ExplanationExplain the square-root cutoff
- 3ExampleTest the complete prime list
- 4ChallengeFind the hole in a prime argument
- 5ExplanationReduce a composite to prime powers
- 6ExampleCount the exponent choices
- 7ChallengeMake the exponents even
- 8ConnectionConnect uniqueness to a prime divisor rule
- 9ChallengeCombine the test and the divisor count
- 10RecapUse the evidence each claim requires
5Follow Euclid into Bézout and integer equations
16 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionKeep both the gcd and how it was made
- 2ExplanationPreserve all common divisors
- 3ExampleRun the remainder sequence
- 4ChallengeUse the gcd to obtain the lcm
- 5ExplanationKeep the original inputs in view
- 6ExampleFinish the back substitution
- 7TipApply each subtraction to both columns
- 8ChallengeRecognize a different valid pair
- 9Key InsightUse one to prove a divisibility claim
- 10ExplanationCheck the reachable right-hand sides
- 11ExampleScale the identity for a particular solution
- 12ExampleDescribe the complete family
- 13ChallengeApply a bound to both coordinates
- 14ConnectionExplain why the family misses none
- 15ChallengeConnect prime factors with the gcd argument
- 16RecapDistinguish construction from completeness
6Find inverses and every congruence solution
12 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionStart with the gcd decision
- 2ExplanationAsk for a product of residue one
- 3ExampleFind an inverse with short Euclidean steps
- 4ChallengeCheck the inverse independently
- 5ExampleSolve with the inverse
- 6ExplanationUse the same gcd to count solutions
- 7ExampleReduce all three values
- 8ExampleLift to the original modulus
- 9ChallengeCompare a reachable and an unreachable target
- 10ConnectionModel a nonzero starting position
- 11ChallengeChoose the full answer for a new dial
- 12RecapFinish in the requested modulus
Divisibility and Modular Arithmetic practice questions
Set 1: Divisibility, residues, and first calculations10 Practice Questions
Question 1 of 10
Show answerHide answer
Question 2 of 10
Show answerHide answer
Question 3 of 10
Show answerHide answer
Question 4 of 10
Show answerHide answer
Question 5 of 10
Show answerHide answer
Question 6 of 10
Show answerHide answer
Question 7 of 10
Show answerHide answer
Question 8 of 10
Show answerHide answer
Question 9 of 10
Show answerHide answer
Question 10 of 10
Show answerHide answer
Set 2: Apply cycles, checksums, and base notation10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 3: Euclid, Bézout, and integer solutions10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 4: Connect proofs, algorithms, and congruences10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Stuck on your own question? Homework Help
Key Terms
B
Back substitution
Base
Bézout coefficients
Bézout’s identity
Binary
Bit
C
Cancellation
Carry
Check digit
Collision
Composite
Congruence
Congruence class
D
Dividend
Divisibility
Divisibility test
Division algorithm
Divisor
Divisor count
E
Euclid’s lemma
Euclidean algorithm
Extended Euclidean algorithm
F
Floor
Fundamental theorem of arithmetic
G
Greatest common divisor
H
Hash function
Hexadecimal
Horner’s method
I
Integer linear combination
Integer parameter
Inverse representative
Invertible class
L
Leading zero
Least common multiple
Least nonnegative representative
Lifting solutions
Linear congruence
Linear congruential generator
Linear Diophantine equation
M
Modular exponentiation
Modular inverse
Modulus
Multiple
Multiplicative identity
O
Octal
P
Pairwise relatively prime
Particular solution
Perfect square
Positional expansion
Power cycle
Prime
Prime factorization
Prime number theorem
Q
Quotient
R
Reduced congruence
Relatively prime
Remainder
Repeated squaring
Residue obstruction
S
Sieve of Eratosthenes
Solution class
T
Trial division
W
Weighted sum
Z
Zero divisor
About this lesson
Make your own Study Materials
Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.