Discrete MathematicsModular Arithmetic and Cryptography2 of 6
Modular Arithmetic and Cryptography · 2
Divisibility Rules and Last Digits
Testing whether a seven-digit number divides cleanly by 4,9,11, or 12, or finding the final digits of a huge power like 72,026, comes down to breaking numbers apart in base 10 and throwing away every piece that leaves a remainder of 0.
1
Divisibility by 2, 5, 10, 4, and 8
We want to tell right away whether a number like 374 is divisible by 5, or whether 5,831,924 is divisible by 4 or 8, without doing long division across the whole number. Remember that a number divides cleanly by n when its remainder is 0, which is when it is congruent to 0(modn).
Divisibility by 2, 5, 10, 4, and 8
Text solution
Split off the tens place to test 2,5, or 10Write 374 as thirty-seven groups of 10 plus the ones digit 4.
374=370+4=(37×10)+4
Drop the tens because 10=2×5Since 10≡0(mod5) (and also mod 2 and mod 10), every group of 10 leaves 0 remainder and disappears.
374≡(37×0)+4=4(mod5)
Because 4≡0(mod5),374 is not divisible by 5 and leaves a remainder of 4.
Split off the hundreds place to test 4A single 10 leaves a remainder mod 4(10=4×2+2≡2(mod4)), so move one place left to 100=4×25≡0(mod4) and split 5,831,924 at the hundreds.
5,831,924=5,831,900+24=(58,319×100)+24
Drop the hundreds and check the last two digitsEvery hundred is congruent to 0(mod4), leaving only 24.
5,831,924≡(58,319×0)+24=24=4×6≡0(mod4)
Since the last two digits divide cleanly by 4, the entire number 5,831,924 is divisible by 4.
Split off the thousands place to test 8Because 100=8×12+4≡4(mod8) still leaves a remainder, move one place further left to 1,000=8×125≡0(mod8), which wipes out everything from the thousands place up and leaves only the last three digits to check.
2
Divisibility by 9, 3, and 11
When we test whether a number is divisible by 9,3, or 11, we can no longer cross out the front of the number, because none of 10,100, or 1,000 divides cleanly by 9,3, or 11. Instead, we want to find how much each power of 10 leaves behind, and use those small remainders to shrink the entire number at once.
Divisibility by 9, 3, and 11
101001000≡?(mod9)≡?(mod9)≡?(mod9)
Text solution
Turn each power of 10 into +1 for mod 9 and mod 3Every power of 10 is just 1 more than a string of 9s (10=9+1,100=99+1,1,000=999+1), and since 9=3×3, those strings of 9s divide cleanly by both 9 and 3.
10i≡1i=1(mod9)and10i≡1(mod3)
Add the digits to test 425(mod9)Each of the 4 hundreds, 2 tens, and 5 ones leaves a remainder of 1 per unit, so the remainder of 425 is the sum of its digits.
425=4(100)+2(10)+5≡4(1)+2(1)+5=11≡1+1=2(mod9)
So 425 leaves a remainder of 2 when divided by 9, and is not divisible by 9.
Turn each power of 10 into (−1)i for mod 11Because 10 is 1 short of 11, we have 10≡−1(mod11), so each step to the left multiplies the place-value remainder by −1 and flips its sign.
Because the alternating sum is a multiple of 11,7,293 divides cleanly by 11.
Prove the rules for any base-10 integer nWrite any integer n with digits dkdk−1…d2d1d0 in its base-10 expansion and substitute the remainder of 10i into each term.
n=dk10k+⋯+d2102+d110+d0
Replacing every 10i with 1(mod9) (or mod 3) gives the digit sum:
Because n and its digit sum (or alternating sum) leave the exact same remainder, n≡0 if and only if that sum is divisible by 9 (or 3, or 11).
Each power of 10 is 1 more than a multiple of 9(9,99,999), so every place-value column leaves +1 mod 9. Beside multiples of 11(11,99,1,001), the powers of 10 alternate between 1 short and 1 over, so the columns flip between +1 and −1.
Moving a unit to the next column keeps its remainder mod 9 the same, but flips the sign of its remainder mod 11.
When you use the mod 11 rule, always label the signs starting with + on the ones digit at the far right and work leftward. Starting on the left will flip every sign whenever the number has an even number of digits.
3
Divisibility by Composite Numbers
Now suppose we want to test whether a number is divisible by a composite number like 6,12,36,45, or 72. Rather than building a brand-new rule, we can split the composite divisor into two smaller factors whose rules we already know, provided those two tests don't check the same prime factor twice.
12=2×6
12=
2
2
3
18=
2
2
3
3
6
18÷12
12=4×3
4
12=
2
2
3
3
Divisibility by Composite Numbers
2
3
4
5
8
9
10
11
612=2×3=2×6?
Text solution
Check why splitting 12 into 2×6 fails on 18A multiple of 12=2×2×3 must contain two factors of 2 and one factor of 3, but 2 and 6=2×3 share a common factor of 2 and both pass on 18 even though 18 has only a single 2.
Split the composite divisor into factors with no common factor greater than 1Grouping all identical primes together prevents any overlap between the two tests.
1245=3×4,=5×9,3672=4×9,=8×9
Test 5,831,924 for divisibility by 12,9, and 11To check 12=4×3, combine the last-two-digits test for 4 with the digit-sum test for 3.
Mod 4:5,831,924≡24=4×6≡0(mod4)(passes 4)
Mod 3 and Mod 9:5+8+3+1+9+2+4=32≡3+2=5≡0(fails 3 and 9)
Since 5,831,924 fails the test for 3, it is not divisible by 12, and its remainder mod 9 is 5. Checking the alternating sum from the right for 11 completes all four opening questions:
Mod 11:4−2+9−1+3−8+5=10≡0(mod11)
So 5,831,924 leaves a remainder of 10 when divided by 11 and is not divisible by 11 either.
4
Last Digits of Large Powers
Now we turn to our second big question: finding the last digit, or the last two digits, of a giant power like 72,026, or the remainder of 82,025 when divided by 9. Because throwing away multiples of 10 leaves the ones digit and throwing away multiples of 100 leaves the tens and ones digits, finding the last digit is just finding the remainder mod 10, and finding the last two digits is just finding the remainder mod 100.
Remember that we can reduce each factor mod n before multiplying:
4,827×9,163=(4,820+7)(9,160+3)≡7×3=21≡1(mod10)
That means we can multiply by 7 one step at a time and throw away the tens (or hundreds) digit after every single multiplication.
Last Digits of Large Powers
72026=…
374=370+4
Text solution
Multiply step by step mod 10 to find the loop for 72,026Keep only the ones digit after each multiplication by 7 until the remainder hits 1.
71727374=49≡9×7=63≡3×7=21≡7,≡9,≡3,≡1(mod10)
Because 74≡1(mod10), the next power 75≡1×7=7(mod10) restarts a repeating loop of 4 digits: 7→9→3→1.
Reduce the exponent mod 4 and evaluateEvery 4 steps in the exponent reset the product to 1, so use the divisibility rule for 4 to find the remainder of 2,026(mod4).
2,026≡26=4×6+2≡2(mod4)
Rewrite 2,026=4×506+2 to group out the 506 full loops of 4:
72,026=74×506+2=(74)506×72≡1506×9=9(mod10)
So the last digit of 72,026 is 9.
Track the loop mod 100 for the last two digits of 72,026Keep only the last two digits after each multiplication by 7.
71727374=343≡43×7=301≡07,≡49,≡43,≡01(mod100)
Since 74≡01(mod100), the last two digits also cycle every 4 steps (07→49→43→01), and the same exponent breakdown gives the last two digits:
72,026=(74)506×72≡1506×49=49(mod100)
So 72,026 ends in the digits 49.
Use a −1 remainder directly for 82,025(mod9)Because 8 is 1 short of 9, replace 8 with −1(mod9) right away instead of writing out a cycle.
8≡−1(mod9)⟹82,025≡(−1)2,025=−1≡8(mod9)
Since the exponent 2,025 is odd, (−1)2,025=−1, which is 1 short of 9 and leaves a remainder of 8.
When you multiply by a single digit over and over and keep only the ones digit, the remainders always fall into a short repeating loop of 1,2, or 4 steps. A large exponent just wraps around that loop.
For any base digit from 1 to 9, multiplying over and over settles into a short loop of 1, 2, or 4 last digits.
Watch out for two common traps on power problems: if your exponent divides cleanly by the loop length (remainder 0), the power lands on the final step of the loop (for base 7 mod 10, that is 74≡1), not on 0; and if the base is already 1 above or 1 below a multiple of the modulus (like 8≡−1(mod9)), swap in +1 or −1 immediately instead of hunting for a loop.
Key concepts
Every problem here comes down to picking how to break the number apart so that nearly all of it turns into 0 or 1:
Ending-digit rules (2,5,10,4,8)
Because 10=2×5,100=4×25, and 1,000=8×125, high enough powers of 10 become 0 in these moduli. Throw away the front of the number and check only the last digit for 2,5, and 10(374≡4(mod5)), the last two digits for 4(5,831,924≡24≡0(mod4)), and the last three digits for 8.
All-digit sum rules (9,3, and 11)
When no power of 10 is congruent to 0, shrink 10 itself before expanding n=dk10k+⋯+d110+d0. For 9 and 3, 10i≡1, so you sum all the digits (425≡4+2+5=11≡2(mod9)). For 11, 10i≡(−1)i, so you take the alternating sum starting with + on the ones digit (7,293≡−7+2−9+3=−11≡0(mod11)).
Composite divisors
Split the divisor into two factors that share no common factors greater than 1, such as 12=3×4 or 72=8×9. Do not use overlapping factors like 12=2×6, which double-count the same factor of 2 and fail on numbers like 18.
Last digits and remainders of large powers
Use (mod10) for the last digit and (mod100) for the last two digits. Reduce the base first; if the base is right next to a multiple of the modulus, substitute ±1 immediately without building a cycle (82,025≡(−1)2,025=−1≡8(mod9)). Otherwise, multiply step by step until you hit 1 (or come back to a remainder you've already seen) to find the loop length, and reduce the exponent modulo that loop length (72,026=(74)506×72≡1506×9=9(mod10)).
5
Practice
1
Without performing long division, find the remainder when 6,418,756 is divided by 8, by 9, and by 11.
Because 1,000=8×125≡0(mod8), throw away the thousands place and above and divide only the last three digits (do not stop at the last two digits 56=8×7, which is the test for 4 and would wrongly give a remainder of 0).
Which power of 10 disappears mod 8, and what happens to 10i in mod 9 versus mod 11? In mod 11, make sure you start your alternating signs at the ones place.
Mod 8Because 1,000=8×125≡0(mod8), throw away the thousands place and above and divide only the last three digits (do not stop at the last two digits 56=8×7, which is the test for 4 and would wrongly give a remainder of 0):
6,418,756≡756=8×94+4≡4(mod8)
Mod 9Since 10i≡1(mod9), sum all the digits:
6,418,756≡6+4+1+8+7+5+6=37≡3+7=10≡1(mod9)
Mod 11Since 10i≡(−1)i(mod11), take the alternating sum starting with + on the ones digit 6 from right to left (starting with − on the ones digit would flip the sign to −3≡8(mod11)):
6,418,756≡+6−5+7−8+1−4+6=3(mod11)
The remainders are 4,1, and 3.
2
To test whether a number is divisible by 24, a student checks whether it is divisible by 4 and by 6, since 24=4×6. Explain why this rule fails, give a counterexample, and state a valid pair of divisibility tests for 24.
Write out the prime factors of 24,4, and 6: how many factors of 2 does 24 require, and how many are actually guaranteed when 4 and 6 both divide a number?
Why it failsA multiple of 24=2×2×2×3 must contain three factors of 2 and one factor of 3. Because 4=2×2 and 6=2×3 share a common factor of 2, the two tests overlap and only guarantee two factors of 2 and one factor of 3 (a multiple of 12) instead of three factors of 2.
Counterexample12 (or 36) is divisible by both 4(12=4×3) and 6(12=6×2), but is not divisible by 24.
Valid testSplit 24 into 3 and 8 (do not pick 2 and 12, which still share a factor of 2 and fail on 12). Because 3 and 8=2×2×2 share no common factors greater than 1, a number is divisible by 24 if and only if it is divisible by both 3 and 8.
3
The seven-digit number 4,1A5,27B is divisible by 72, where A and B are single digits (0 through 9). Find A and B.
Substitute B=2 into the digit sum (forgetting to include B=2 in the sum gives 19+A=27 and the wrong answer A=8).
Split 72 into two factors that share no common factors greater than 1. Which of the two tests involves only one of the unknown digits so you can solve for it first?
Split 72Since 72=8×9 and 8 and 9 share no common factors greater than 1, the number must be divisible by both 8 and 9.
Find B using mod 8For divisibility by 8, the last three digits 27B must be a multiple of 8 (be careful not to check only the last two digits 7B as in the mod 4 rule, which would also allow B=6). Since 272=8×34 is the only multiple of 8 between 270 and 279, we get B=2.
Find A using mod 9Substitute B=2 into the digit sum (forgetting to include B=2 in the sum gives 19+A=27 and the wrong answer A=8):
4+1+A+5+2+7+2=21+A≡0(mod9)
The only multiple of 9 reachable with a single digit A is 27, giving 21+A=27.A=6 and B=2.
4
Find the last digit of 34,719.
Use the divisibility rule for 4 on the exponent 4,719 by keeping its last two digits (do not reduce the exponent mod 10 to get 9, and do not stop at the exponent's remainder 3 as if it were the final answer).
Multiply powers of 3 in mod 10 until the ones digit hits 1. How long is the loop, and what rule gives the remainder of the exponent 4,719 modulo that loop length?
Find the loop mod 10Multiply by 3 and keep only the last digit at each step:
31323334=27≡7×3=21≡3,≡9,≡7,≡1(mod10)
The last digits repeat in a cycle of 4:3→9→7→1.
Reduce the exponent mod 4Use the divisibility rule for 4 on the exponent 4,719 by keeping its last two digits (do not reduce the exponent mod 10 to get 9, and do not stop at the exponent's remainder 3 as if it were the final answer):
4,719≡19=4×4+3≡3(mod4)
Evaluate mod 10Break out the 1,179 full loops of 4:
34,719=(34)1,179×33≡11,179×7=7(mod10)
The last digit is 7.
5
Find the last two digits of 6071,535.
Multiply by 7 and keep the last two digits at each step (keep both the tens and ones digits so you don't drop the 4 in 343≡43 and get 03).
Which modulus gives the last two digits of a number, and what does the base 607 simplify to in that modulus before you take any powers?
Reduce the base mod 100Throw away the hundreds place of the base first:
607=600+7≡7(mod100)
Find the loop mod 100Multiply by 7 and keep the last two digits at each step (keep both the tens and ones digits so you don't drop the 4 in 343≡43 and get 03):
71727374=343≡43×7=301≡07,≡49,≡43,≡01(mod100)
The last two digits repeat in a cycle of 4.
Reduce the exponent mod 4 and evaluateCheck the last two digits of the exponent 1,535 mod 4:
1,535≡35=4×8+3≡3(mod4)
Substitute 1,535=4×383+3 into the power mod 100:
6071,535≡71,535=(74)383×73≡1383×43=43(mod100)
The last two digits are 43.
6
Find the remainder when 212,025+102,025 is divided by 11.
Notice that both 21 and 10 are 1 short of a multiple of 11 (be careful not to write 21≡+1(mod11) by confusing 22−1 with 22+1, which would cancel the two terms to 0).Add the two terms and add 11 to convert the negative remainder (don't just drop the minus sign to get 2).
Look at how close the bases 21 and 10 are to multiples of 11(22 and 11) so you can rewrite both bases before raising them to the 2,025th power.
Rewrite each base using negative remainders mod 11Notice that both 21 and 10 are 1 short of a multiple of 11 (be careful not to write 21≡+1(mod11) by confusing 22−1 with 22+1, which would cancel the two terms to 0):
2110=22−1≡−1(mod11),=11−1≡−1(mod11)
Evaluate the odd powers and convert to a positive remainderBecause the exponent 2,025 is odd, (−1)2,025=−1. Add the two terms and add 11 to convert the negative remainder (don't just drop the minus sign to get 2):
Let n=dk10k+⋯+d2102+d110+d0 be the base-10 expansion of a positive integer n. Using congruence mod 4, prove that n≡2d1+d0(mod4), and conclude that n is divisible by 4 if and only if 2d1+d0 is divisible by 4.
Find the remainder of 10i(mod4) separately for i≥2 and for i=1, then substitute both into the base-10 expansion of n.
Reduce the powers of 10 mod 4Since 100=4×25≡0(mod4), every power 10i with i≥2 can be factored as 100×10i−2 and becomes 0(mod4):
10i=100×10i−2≡0×10i−2=0(mod4)for all i≥2
For the tens place (i=1), 10 is not congruent to 0 or 1 mod 4 (treating 10≡1(mod4) like the mod 9 rule would wrongly give d1+d0):
10=4×2+2≡2(mod4)
Substitute into the base-10 expansion of nReplace 10i for i≥2 with 0 and 10 with 2 in the expansion of n:
Conclude the "if and only if" divisibility testBecause n≡2d1+d0(mod4),n and 2d1+d0 leave the exact same remainder when divided by 4. Therefore, n≡0(mod4) if and only if 2d1+d0≡0(mod4), which means n is divisible by 4 if and only if 2d1+d0 is divisible by 4.