Discrete MathematicsDivisibility, Primes and Greatest Common Divisors1 of 6
Divisibility, Primes and Greatest Common Divisors · 1
Divisibility and the Division Algorithm
In discrete math, we work with integers rather than fractions or decimals, so we need a clean way to say when one whole number fits evenly into another, and how to handle the leftover steps when it doesn't.
1
What Divisibility Means
One integer divides another when we can build the second number completely out of whole copies of the first, with nothing left over.
What Divisibility Means
To work with divisibility in equations and proofs without using fractions, we define the vertical bar ∣ as a multiplication statement:
a∣bmeansb=a⋅k for some integer k
Notice that a∣b is a true-or-false sentence ("a divides b"), not a fraction or an operation like ab.
Example: Does 4∣0? Does 0∣4?
Text solution
Rewrite 4∣0 as multiplicationWe look for an integer k that you can multiply by 4 to get 0.
0=4⋅k⟹k=0
Rewrite 0∣4 as multiplicationMultiplying 0 by any integer k always gives 0, so no integer k can produce 4.
4=0⋅k(no integer solution k)
So 4∣0 is true (in fact, every integer divides 0), while 0∣4 is false (0∤4).
2
Rules of Divisibility and Linear Combinations
Because divisibility is just multiplication by an integer, chaining multiples together or combining two multiples of the same block a always produces another multiple of a.
Rules of Divisibility and Linear Combinations
Writing out the multiplication equations gives two core rules for any integers a,b,c:
If a∣b and b∣c, then a∣c
If a∣b and a∣c, then a∣(linear combinationbx+cy)for any integers x,y
Example: If a positive integer d divides both n+3 and n+10, what could d be?
Text solution
Combine the two expressions to cancel nSince d divides both n+10 and n+3, it must also divide their difference.
1⋅(n+10)+(−1)⋅(n+3)=7
Find the positive divisors of the resultBecause d must divide 7 and d is positive, only two values are possible.
d∣7⟹d=1 or d=7
So d can only be 1 or 7, no matter which integer n we start with.
As n changes, the two bars n+3 and n+10 grow or shrink together, while the overhang between them stays a fixed block of length 7 that any common divisor d must also fit into evenly.
As the shared piece changes, both bars grow and shrink together, keeping a fixed overhang of 7 between them.
3
The Division Algorithm
When a positive integer d does not divide n evenly, the Division Algorithm gives the one consistent way to write n using the nearest multiple of d at or to the left of n and the forward steps left over.
The Division Algorithm
When we divide any integer n by a positive integer d, there is exactly one quotient q and one remainder r that work:
n=divisord⋅quotientq+remainderrwhere 0≤r<d
Example: Find the quotient q and remainder r when n=17 is divided by d=5.
Text solution
Stop at the multiple of 5 at or to the left of 17On a number line marked with multiples of 5,17 lies between 15 and 20, so we start at 15.
5⋅3=15
Count the steps forward to 17Walking 2 steps to the right reaches 17 with a remainder between 0 and 5.
17=5(3)+2(0≤2<5)
So the quotient is q=3 and the remainder is r=2.
4
Dividing Negative Numbers
When n is negative, we still need a non-negative remainder (0≤r<d), which means finding the multiple of d at or immediately to the left of n on the negative number line rather than just putting minus signs on the positive answer.
Dividing Negative Numbers
Example: Find the quotient q and remainder r when n=−17 and n=−15 are divided by d=5.
Text solution
Start at the multiple of 5 to the left of −17Because −17 falls between −20 and −15, stopping at −15 would overshoot to the right, so we go left to −20.
5⋅(−4)=−20
Walk forward to −17Stepping 3 units to the right reaches −17 with a valid remainder 0≤3<5.
−17=5(−4)+3
Check whether −15 is already a multiple of 5Because −15 lands directly on a multiple of 5, we stay right there with 0 extra steps.
−15=5(−3)+0
For −17 divided by 5, the quotient is q=−4 and the remainder is r=3; for −15 divided by 5, the quotient is q=−3 and the remainder is r=0.
Because the remainder arrow +r always points forward (0≤r<5), any n between −20 and −15 has to start at −20(q=−4), while −15 itself already sits on a multiple (q=−3,r=0).
Because the remainder always steps forward from a multiple of 5 at or to the left of your number, every integer between -20 and -15 starts from -20, not -15.
5
Using `div` and `mod` to Count Multiples
We use `div` and `mod` as shorthand for the quotient and remainder, and for positive numbers, `div` gives a direct way to count how many multiples of d fit up to n without listing them.
Using div and mod to Count Multiples
When n=d⋅q+r with 0≤r<d:quotientn div d=qremaindern mod d=r
Example: How many positive multiples of 7 are there up to 250?
Text solution
Divide 250 by 7 using the Division AlgorithmWriting 250 in terms of multiples of 7 identifies the last multiple of 7 at or before 250.
250=7(35)+5
Read the quotient as the count of multiplesThe 35th positive multiple is 7⋅35=245, with 5 steps left over before 250.
250 div 7=35
So there are 35 positive multiples of 7 up to 250.
6
Proof by Cases with the Division Algorithm
To prove a statement about all infinitely many integers when a divisor d is involved, we use the Division Algorithm to sort every integer n into a few cases based on its remainder 0,1,…,d−1. Remember, splitting integers into even (n=2q) and odd (n=2q+1) is this exact idea with step-size d=2, where 0≤r<2 allows only r=0 or r=1.
Proof by Cases with the Division Algorithm
Example: Show that for any integer n, when n2 is divided by 3, the remainder is 0 or 1, never 2.
Text solution
Split all integers into three cases using d=3Since 0≤r<3, any integer n has remainder 0,1, or 2 when divided by 3.
n=3q,n=3q+1,orn=3q+2
Case 1 (n=3q)Squaring n and factoring out 3 gives a multiple of 3 with remainder 0.
n2=(3q)2=9q2=3(3q2)+0
Case 2 (n=3q+1)Expanding the square and factoring 3 out of the first two terms leaves remainder 1.
n2=(3q+1)2=9q2+6q+1=3(3q2+2q)+1
Case 3 (n=3q+2)Because +4 is at least 3, we split 4 into 3+1 before factoring out 3, which again leaves remainder 1.
n2=(3q+2)2=9q2+12q+4=9q2+12q+3+1=3(3q2+4q+1)+1
In every possible case, n2 is either 3k+0 or 3k+1 for an integer k, so dividing n2 by 3 can only leave a remainder of 0 or 1, never 2.
When the unit squares of an n×n grid are grouped into strips of 3, any 2×2 leftover corner splits into one more L-shaped group of 3 plus 1 unit square, so n2 leaves either 0 or 1 square left over for every integer n.
Every square grid bundles into groups of 3 with only 0 or 1 square left in the corner, never 2.
Key concepts
Turn divisibility into multiplication (a∣b⟺b=a⋅k)
Whenever a problem asks whether one number divides another or asks you to prove a divisibility statement, write the multiplication equation first. That immediately settles zero cases (4∣0 because 0=4⋅0, whereas 0∤4 because 4=0⋅k has no integer solution) and lets you chain or combine multiples. If an unknown divisor d divides two expressions with n (like d∣n+3 and d∣n+10), use a linear combination bx+cy to cancel n(1(n+10)−1(n+3)=7, so d∣7).
Start at the multiple at or to the left (n=dq+r with 0≤r<d)
The quotient n div d=q tells you which multiple of d you stop at, and the remainder n mod d=r counts the forward steps to n. When n is negative and falls between multiples, step one multiple further negative so the remainder stays positive (−17=5(−4)+3, giving −17 div 5=−4 and −17 mod 5=3). Don't step further left if n already lands directly on a multiple of d(−15=5(−3)+0 already has r=0).
Count multiples with `div`, or prove for all n by cases on r
For positive n,n div d counts how many positive multiples of d fit up to n(250 div 7=35). When a question asks you to prove something about every integer n involving a divisor d, match the step-size d to break all integers into the d cases n=dq,dq+1,…,dq+(d−1).
7
Practice
1
Determine whether each statement is true or false by translating it into a multiplication equation b=a⋅k for some integer k: (a) −6∣24, (b) 0∣9, (c) 0∣0.
Put the second number on the left of the equals sign (b=a⋅k) and ask whether any integer k makes the equation true.
(a)Rewriting −6∣24 gives 24=(−6)⋅k, which is satisfied by the integer k=−4.True.
(b)Rewriting 0∣9 gives 9=0⋅k. (Watch out: don't swap the two numbers into 0=9⋅k, which tests 9∣0 instead of 0∣9 and gives the wrong answer True.) Since 0⋅k=0 for every integer k, there is no integer solution. False.
(c)Rewriting 0∣0 gives 0=0⋅k. (Don't treat the vertical bar as the undefined fraction 00, which would make you answer False.) This multiplication equation holds for any integer k (for instance, k=1). True.
2
Find the quotient n div d and the remainder n mod d when (a) n=−29 and d=6, and (b) n=−24 and d=6.
Watch out: just putting minus signs on 29=6(4)+5 gives −29=6(−4)−5, which overshoots to −24 and gives the wrong quotient −4 and negative remainder −5.
Locate n relative to the multiples of 6 on the negative number line (−30,−24,−18,…) and make sure the remainder satisfies 0≤r<6.
(a)On the number line, −29 sits between −30 and −24, so the multiple of 6 immediately to the left of −29 is −30=6(−5), which gives −29=6(−5)+1 with 0≤1<6. (Watch out: just putting minus signs on 29=6(4)+5 gives −29=6(−4)−5, which overshoots to −24 and gives the wrong quotient −4 and negative remainder −5.) Thus −29 div 6=−5 and −29 mod 6=1.
(b)Here −24=6(−4)+0 lands directly on a multiple of 6. (Don't automatically step one multiple further left to −30=6(−5), which would leave r=6 and violate r<6.) Thus −24 div 6=−4 and −24 mod 6=0.
3
How many multiples of 8 are there from 100 to 300, inclusive?
Watch out: don't add +1 as if you were subtracting endpoints, which gives 26. The 12 multiples up to 99 are purely the ones we want to remove, so 37−12 already keeps every multiple from 100 to 300.
Count all positive multiples of 8 up to 300, then subtract the positive multiples of 8 that come strictly before 100.
The number of positive multiples of 8 up to 300 is 300 div 8=37 (since 300=8⋅37+4). The number of positive multiples of 8 strictly below 100 (that is, up to 99) is 99 div 8=12 (since 99=8⋅12+3). Subtracting the 12 multiples below 100 from the 37 multiples up to 300 gives 37−12. (Watch out: don't add +1 as if you were subtracting endpoints, which gives 26. The 12 multiples up to 99 are purely the ones we want to remove, so 37−12 already keeps every multiple from 100 to 300.) The number of multiples is 25.
4
Suppose n is an integer and d is a positive integer such that d∣(2n+1) and d∣(3n+7). What are the possible values of d?
Watch out: if you forget to multiply the constant terms 7 and 1 by 2 and −3, you get 7−1=6 and the wrong divisors 1,2,3,6.
Choose integer multipliers x and y in x(3n+7)+y(2n+1) so the n terms match and cancel out.
Since d divides both 2n+1 and 3n+7,d must divide any linear combination of them. To cancel n, multiply 3n+7 by 2 and 2n+1 by −3:
2(3n+7)+(−3)(2n+1)=(6n+14)−(6n+3)=11
(Watch out: if you forget to multiply the constant terms 7 and 1 by 2 and −3, you get 7−1=6 and the wrong divisors 1,2,3,6.) Thus d∣11, and since d is a positive integer, d=1 or 11.
5
Prove that for all integers a,b,c,d, if a∣b and c∣d, then ac∣bd.
Translate a∣b and c∣d into two multiplication equations using two different integer variables, then multiply the equations together.
Let a,b,c,d be integers such that a∣b and c∣d. By the definition of divisibility, b=ak for some integer k, and d=cm for some integer m. (Watch out: don't reuse the same letter k in both b=ak and d=ck, because the two quotients don't have to be equal.) Multiplying the two equations gives:
bd=(ak)(cm)=(ac)(km)
Since k and m are integers, their product km is also an integer, so ac∣bd.
6
Use the Division Algorithm with d=3 to prove that for every integer n,3∣n(n+1)(n+2).
Write out the three cases for n when divided by 3(n=3q,3q+1,3q+2) and notice which one of the three factors n,n+1, or n+2 becomes a multiple of 3 in each case.
By the Division Algorithm with d=3, any integer n leaves remainder 0,1, or 2 when divided by 3, giving three cases for some integer q:
Case 1 (n=3q)Then n(n+1)(n+2)=3q(3q+1)(3q+2)=3⋅[q(3q+1)(3q+2)], which is 3 times an integer.
Case 2 (n=3q+1)Then the third factor is n+2=(3q+1)+2=3q+3=3(q+1). (Watch out: don't expand the entire cubic product. Just factor 3 out of the single factor 3q+3.) Substituting gives n(n+1)(n+2)=(3q+1)(3q+2)⋅3(q+1)=3⋅[(3q+1)(3q+2)(q+1)], which is 3 times an integer.
Case 3 (n=3q+2)Then the middle factor is n+1=(3q+2)+1=3q+3=3(q+1), so n(n+1)(n+2)=(3q+2)⋅3(q+1)(3q+4)=3⋅[(3q+2)(q+1)(3q+4)], which is 3 times an integer.
In every case, n(n+1)(n+2) is 3 times an integer, so 3∣n(n+1)(n+2).