Number Theory Toolkit

Study Sheet

Number Theory Toolkit

Divisibility, primes, and remainders

Divisibility Rules

Tip
The rules worth memorizing

Divisible by 3 or 9 when the digit sum is; by 4 when the last two digits form a multiple of 44; by 8 when the last three do; by 11 when the alternating digit sum (units −- tens ++ hundreds …\dots) is a multiple of 1111.

In plain terms. Instead of doing long division, just add or peek at a few digits. It is a shortcut to answer "does this divide evenly?" in one glance.

Example. Is 8,5148{,}514 divisible by 99? Digit sum =8+5+1+4=18= 8+5+1+4 = 18, and 1818 is a multiple of 99, so yes.

Every rule works the same way: most of the number is a multiple of the divisor, so only a few digits can affect the remainder. 100100 is a multiple of 44, so 44 sees only the last two digits; 10001000 is a multiple of 88, so 88 sees the last three; every power of 1010 is one more than a multiple of 99, so 99 sees the digit sum. To test a composite divisor, split it into factors that share nothing — 12=3⋅412 = 3\cdot4, 36=4⋅936 = 4\cdot9 — and test each.

Concept
Why the digit-sum rule works

Because 10≡1(mod9)10 \equiv 1 \pmod 9, every power of ten leaves remainder 11, so a number and its digit sum leave the same remainder mod 99 (and mod 33).

In plain terms. Each "1010" is just "one more than a nine," so tens, hundreds, and so on don't change the remainder when you divide by 99 — only the digits themselves do.

Example. For 2323: 23=2⋅10+3=2⋅9+2+323 = 2\cdot 10 + 3 = 2\cdot 9 + 2 + 3, so its remainder mod 99 is 2+3=52+3 = 5, exactly the digit sum.

Example
Worked: a missing digit

The four-digit number 42□842\square8 is divisible by 99. What digit is in the box?

Step 1 — the rule: the digit sum must be a multiple of 99.

Step 2 — the known digits give 4+2+8=144 + 2 + 8 = 14.

Step 3 — a single digit dd makes the sum 14+d14 + d, which is between 1414 and 2323; the only multiple of 99 there is 1818, so d=4d = 4. Check: 4248=9⋅4724248 = 9\cdot472.

Example
Worked: two tests at once

What is the largest digit dd for which 57d457d4 is divisible by 1212?

Step 1 — split 12=3⋅412 = 3\cdot4; the factors share nothing, so the number must pass both tests.

Step 2 — the test for 44 looks at the last two digits, d4d4: 04,24,44,64,8404, 24, 44, 64, 84 are multiples of 44 and 14,34,54,74,9414, 34, 54, 74, 94 are not, so dd is even.

Step 3 — the test for 33: 5+7+d+4=16+d5 + 7 + d + 4 = 16 + d must be a multiple of 33, so dd is 22, 55 or 88.

Step 4 — both: d=2d = 2 or 88, and the largest is 88. Check: 5784=12⋅4825784 = 12\cdot482.

Example
Worked: the rule for 11

For which digit AA is the five-digit number 7A5A27A5A2 divisible by 1111?

Step 1 — the alternating sum from the units digit: 2−A+5−A+7=14−2A2 - A + 5 - A + 7 = 14 - 2A.

Step 2 — it must be a multiple of 1111. Since AA is a digit, 14−2A14 - 2A lies between −4-4 and 1414, so it is 00 or 1111.

Step 3 — 14−2A=1114 - 2A = 11 has no whole-number solution, and 14−2A=014 - 2A = 0 gives A=7A = 7. Check: 77572=11⋅705277572 = 11\cdot7052. The rule works because 1010 is one less than 1111, so the powers of 1010 alternate between one more and one less than multiples of 1111.

Side note
Where it goes wrong

Combining tests whose divisors share a factor. "Divisible by 44 and by 66, so divisible by 2424" is false: 1212 is divisible by both and not by 2424. The combined test works only for divisors with no common factor — use 33 and 88 for 2424, not 44 and 66.

Try it
Try it: divisible by 36

The four-digit number 5d1d5d1d (the same digit dd in both places) is divisible by 3636. Find dd.

Show the answer

36=4⋅936 = 4\cdot9. Test for 44: the last two digits 1d1d must be a multiple of 44, so d=2d = 2 or 66 (1212 or 1616). Test for 99: the digit sum 5+d+1+d=6+2d5 + d + 1 + d = 6 + 2d must be a multiple of 99; d=2d = 2 gives 1010, d=6d = 6 gives 1818. So d=6d = \mathbf{6}: 5616=36⋅1565616 = 36\cdot156.

Primes and Factorization

Tip
Prime factorization is the master key

Write n=p1a1⋯pkakn = p_1^{a_1}\cdots p_k^{a_k}. Then the number of divisors is (a1+1)⋯(ak+1)(a_1+1)\cdots(a_k+1), and the sum of divisors is ∏piai+1−1pi−1\prod \dfrac{p_i^{a_i+1}-1}{p_i-1}.

In plain terms. Break a number into its prime "building blocks." Once you know the blocks, counting or adding up all its factors is just plugging into a formula.

Example. 72=23⋅3272 = 2^3\cdot 3^2, so it has (3+1)(2+1)=12(3+1)(2+1) = 12 divisors, and their sum is 24−11⋅33−12=15⋅13=195\dfrac{2^4-1}{1}\cdot\dfrac{3^3-1}{2} = 15\cdot 13 = 195.

Why the divisor formula works: a divisor of 23⋅322^3\cdot3^2 must be built from the same primes with exponents no larger, so it is 2a3b2^a3^b with aa chosen from 0,1,2,30, 1, 2, 3 and bb from 0,1,20, 1, 2 — four choices times three choices. Every question about divisors, perfect squares, and common factors becomes a question about exponents, which is why factoring comes first.

Concept
Checking primality quickly

To test whether nn is prime you only need trial divisors up to n\sqrt n: if n=abn = ab with a≤ba\le b then a≤na \le \sqrt n.

In plain terms. A factor pair always has one member no bigger than the square root, so you never need to test past n\sqrt n — that cuts the work enormously.

Example. To check 9797: 97<10\sqrt{97} < 10, so only test 2,3,5,72,3,5,7. None divide it, so 9797 is prime.

Example
Worked: a factor tree
47896350422233
Split any way you like; the circled primes at the ends are always the same.

Write 504504 as a product of primes and count its divisors.

Step 1 — split into any two factors, 504=8⋅63504 = 8\cdot63, and keep splitting until every end is prime: 8=2⋅2⋅28 = 2\cdot2\cdot2 and 63=7⋅9=7⋅3⋅363 = 7\cdot9 = 7\cdot3\cdot3.

Step 2 — collect: 504=23⋅32⋅7504 = 2^3\cdot3^2\cdot7.

Step 3 — the divisor count is (3+1)(2+1)(1+1)=24(3 + 1)(2 + 1)(1 + 1) = 24. Starting with 504=4⋅126504 = 4\cdot126 or 504=12⋅42504 = 12\cdot42 gives a different tree with the same primes at the ends — that is the uniqueness of prime factorization.

Example
Worked: exactly ten divisors

What is the smallest positive integer with exactly 1010 divisors?

Step 1 — work backwards from the formula: 1010 divisors means the product of (exponent +1+ 1) is 1010, so the exponents are 99 (one prime) or 44 and 11 (two primes).

Step 2 — smallest of each shape: 29=5122^9 = 512; and 24⋅3=482^4\cdot3 = 48, putting the bigger exponent on the smaller prime (34⋅2=1623^4\cdot2 = 162 is larger).

Step 3 — the answer is 4848. Its divisors: 1,2,3,4,6,8,12,16,24,481, 2, 3, 4, 6, 8, 12, 16, 24, 48.

Example
Worked: making a perfect cube

What is the smallest positive integer kk for which 180k180k is a perfect cube?

Step 1 — factor: 180=22⋅32⋅5180 = 2^2\cdot3^2\cdot5.

Step 2 — a perfect cube has every exponent a multiple of 33, so raise each exponent to the next multiple of 33: 22→232^2 \to 2^3 needs one 22, 32→333^2 \to 3^3 needs one 33, 51→535^1 \to 5^3 needs two 55s.

Step 3 — k=2⋅3⋅52=150k = 2\cdot3\cdot5^2 = 150, and 180⋅150=27000=303180\cdot150 = 27000 = 30^3.

Side note
Where it goes wrong

Treating 11 as a prime (it is not — it has only one divisor), and trusting that a number "looks prime". 51=3⋅1751 = 3\cdot17 and 91=7⋅1391 = 7\cdot13 fool people under time pressure; test primes up to the square root before writing "prime".

Try it
Try it: odd divisors

How many of the positive divisors of 504504 are odd?

Show the answer

504=23⋅32⋅7504 = 2^3\cdot3^2\cdot7. An odd divisor uses no factor of 22: it is 3b7c3^b7^c with b∈{0,1,2}b \in \{0, 1, 2\} and c∈{0,1}c \in \{0, 1\}, so there are 3⋅2=63\cdot2 = \mathbf{6}: 1,3,7,9,21,631, 3, 7, 9, 21, 63.

GCD, LCM, and Units Digits

Tip
The GCD–LCM identity
22 · 3312 = 2 · 2 · 318 = 2 · 3 · 3
Shared primes (the overlap) multiply to the gcd, 66; all the primes multiply to the lcm, 3636.

For positive integers, gcd⁡(a,b)⋅lcm⁡(a,b)=ab\gcd(a,b)\cdot\operatorname{lcm}(a,b) = ab.

In plain terms. The greatest common divisor and least common multiple always multiply to give the two numbers' product — so knowing one gives the other.

Example. gcd⁡(12,18)=6\gcd(12,18) = 6, so lcm⁡(12,18)=12⋅186=36\operatorname{lcm}(12,18) = \dfrac{12\cdot 18}{6} = 36.

Why the identity holds: in the prime factorizations, the gcd takes the SMALLER exponent of each prime and the lcm the LARGER. For 12=22⋅312 = 2^2\cdot3 and 18=2⋅3218 = 2\cdot3^2 the gcd is 2⋅3=62\cdot3 = 6 and the lcm is 22⋅32=362^2\cdot3^2 = 36. For each prime, smaller exponent plus larger exponent equals the two exponents added, so gcd⁡⋅lcm\gcd\cdot\text{lcm} has exactly the primes of abab.

Concept
Units digits cycle
77¹, 7⁵, …97², 7⁶, …37³, 7⁷, …17⁴, 7⁸, …× 7
Each step multiplies by 77; after four steps the units digit is back where it started.

The last digit of ana^n repeats with a period dividing 44: powers of 22 cycle 2,4,8,62,4,8,6; of 33 cycle 3,9,7,13,9,7,1.

In plain terms. Last digits go in a short repeating loop, so you just find where your exponent lands in the loop instead of computing the whole power.

Example. Last digit of 71007^{100}: the cycle for 77 has length 44, and 100≡0(mod4)100\equiv 0\pmod 4, so it matches 747^4, whose last digit is 11.

Example
Worked: two bells

One bell rings every 1212 minutes and another every 1818 minutes. They ring together at noon. When do they next ring together?

Step 1 — the first bell rings at multiples of 1212 minutes after noon, the second at multiples of 1818.

Step 2 — they coincide at common multiples, first at lcm(12,18)=36\text{lcm}(12, 18) = 36.

Step 3 — 12:3612{:}36. (Using the gcd here is the classic slip: 66 minutes after noon neither bell rings.)

Example
Worked: the missing number

Two positive integers have greatest common divisor 66 and least common multiple 180180. One of them is 3636. What is the other?

Step 1 — the identity: gcd⁡⋅lcm=ab\gcd\cdot\text{lcm} = ab, so 6⋅180=36b6\cdot180 = 36b.

Step 2 — b=1080/36=30b = 1080/36 = 30.

Step 3 — check, because the identity can give a number that fails: gcd⁡(36,30)=6\gcd(36, 30) = 6 and lcm(36,30)=180\text{lcm}(36, 30) = 180. Both hold.

Example
Worked: the largest square tile

A floor measures 8484 by 6060 units. It is to be covered exactly by equal square tiles, as large as possible. How many tiles are needed?

Step 1 — the tile's side must divide both 8484 and 6060, and the largest such side is gcd⁡(84,60)=12\gcd(84, 60) = 12 (84=22⋅3⋅784 = 2^2\cdot3\cdot7, 60=22⋅3⋅560 = 2^2\cdot3\cdot5).

Step 2 — the floor holds 84/12=784/12 = 7 tiles along one side and 60/12=560/12 = 5 along the other.

Step 3 — 7⋅5=357\cdot5 = 35 tiles.

Side note
Where it goes wrong

Using gcd⁡⋅lcm=\gcd\cdot\text{lcm} = product for three numbers. For 2,4,62, 4, 6: gcd 22, lcm 1212, product 2424 — but 2⋅4⋅6=482\cdot4\cdot6 = 48. The identity is a fact about PAIRS, because only for two numbers do "smaller exponent" and "larger exponent" account for every exponent.

Try it
Try it: units digit of a sum

What is the units digit of 32025+720253^{2025} + 7^{2025}?

Show the answer

Both cycles have length 44: 3,9,7,13, 9, 7, 1 and 7,9,3,17, 9, 3, 1. Since 2025=4⋅506+12025 = 4\cdot506 + 1, each power matches the first entry of its cycle: units digits 33 and 77. Their sum ends in 3+7=103 + 7 = 10, so the units digit is 0\mathbf{0}.

Counting Divisors, and the Last Digit

Tip
How many divisors a number has
3⁰3¹3²2⁰1392¹26182²412362³824724 × 3= 12 divisors
Each divisor of 7272 is one cell: a choice of power of 22 times a choice of power of 33.

Factor n=p1a1p2a2⋯n = p_1^{a_1}p_2^{a_2}\cdots; then nn has (a1+1)(a2+1)⋯(a_1+1)(a_2+1)\cdots divisors, their sum is ∏piai+1−1pi−1\prod \dfrac{p_i^{a_i+1}-1}{p_i-1}, and their product is nd(n)/2n^{d(n)/2}.

The count comes straight from the factorization: each divisor chooses an exponent for each prime independently, from 00 to aia_i. So 72=23⋅3272 = 2^3\cdot3^2 has (3+1)(2+1)=12(3+1)(2+1) = 12 divisors, and their sum is 24−11⋅33−12=15⋅13=195\dfrac{2^4-1}{1}\cdot\dfrac{3^3-1}{2} = 15\cdot13 = 195. A perfect square is exactly a number with an ODD divisor count, because only then is some ai+1a_i+1 product odd — that fact alone answers a whole family of contest questions about lockers and lightbulbs.

Tip
Units digits cycle

The units digit of nkn^k repeats with period dividing 44: 22 cycles 2,4,8,62,4,8,6; 33 cycles 3,9,7,13,9,7,1; 77 cycles 7,9,3,17,9,3,1; 4,94,9 cycle with period 22; 0,1,5,60,1,5,6 never change.

To find the units digit of 720267^{2026}, divide the exponent by the cycle length: 2026=4⋅506+22026 = 4\cdot506 + 2, so it matches 727^2, units digit 99. Two traps: an exponent that is a multiple of the cycle length lands on the LAST entry of the cycle, not the first (747^{4} ends in 11, not 77); and the cycle is about the units digit only — for the last TWO digits you need to work modulo 100100.

Example
Worked: divisors and a last digit together

How many divisors does 600600 have, and what is the units digit of 36003^{600}?

Step 1 — factor: 600=23⋅3⋅52600 = 2^3\cdot3\cdot5^2, so d(600)=4⋅2⋅3=24d(600) = 4\cdot2\cdot3 = 24 divisors.

Step 2 — the units digit of 3k3^k cycles 3,9,7,13,9,7,1 with period 44, and 600=4⋅150600 = 4\cdot150 exactly, so 36003^{600} matches the last entry of the cycle: units digit 11. Both halves are the same idea — read the answer off the structure instead of computing the number.

Example
Worked: an odd number of divisors

How many integers from 11 to 6060 have an odd number of positive divisors?

Step 1 — divisors pair up as dd and n/dn/d, so the count is odd exactly when one divisor is paired with itself, d=n/dd = n/d, which means n=d2n = d^2 is a perfect square.

Step 2 — the squares up to 6060 are 1,4,9,16,25,36,491, 4, 9, 16, 25, 36, 49.

Step 3 — the answer is 77. No divisor counting was needed; the pairing did the work.

Side note
The divisor-count trick for perfect squares

Because divisors pair up as dd and n/dn/d, the count is even UNLESS some divisor pairs with itself, i.e. nn is a perfect square. That is why "which lockers stay open?" has the answer "the perfect-square ones".

Try it
Try it: count and last digit

How many divisors does 360360 have, and what is the units digit of 2352^{35}?

Show the answer

360=23⋅32⋅5360 = 2^3\cdot3^2\cdot5 gives 4⋅3⋅2=244\cdot3\cdot2 = 24 divisors. For 2352^{35}: 35=4⋅8+335 = 4\cdot8 + 3, so it matches 232^3 — units digit 88.

Putting It Together

Example
Worked: exactly three divisors

How many positive integers less than 100100 have exactly three positive divisors?

Step 1 — translate with the formula: the product of (exponent +1+ 1) is 33, and 33 is prime, so there is one prime with exponent 22: the number is p2p^2.

Step 2 — its divisors are 1,p,p21, p, p^2, exactly three.

Step 3 — p2<100p^2 < 100 means p<10p < 10: p=2,3,5,7p = 2, 3, 5, 7, giving 4,9,25,494, 9, 25, 49. The answer is 44.

Example
Worked: a number made by repeating

Show that every six-digit number of the form abcabcabcabc (such as 358358358358) is divisible by 77, 1111 and 1313.

Step 1 — write it as a product: abcabc=abc⋅1000+abc=abc⋅1001abcabc = abc\cdot1000 + abc = abc\cdot1001.

Step 2 — factor 1001=7⋅11⋅131001 = 7\cdot11\cdot13.

Step 3 — so abcabc=abc⋅7⋅11⋅13abcabc = abc\cdot7\cdot11\cdot13 is divisible by all three, whatever the digits. For example 358358=358⋅1001358358 = 358\cdot1001. Seeing the structure — "repeat" means "multiply by 10011001" — replaces three long divisions.

Tip
Which tool?

Divisors, squares, cubes, gcd and lcm: factor into primes first and read the exponents. Divisibility by a small number: a digit rule. Last digit of a power: the cycle. A number with a visible pattern: write the pattern as a product.

Try it
Try it: six divisors

What is the smallest positive integer that has exactly 66 positive divisors and is divisible by 55?

Show the answer

6=66 = 6 or 3⋅23\cdot2, so the number is p5p^5 or p2qp^2q. It must contain 55. Options: 55=31255^5 = 3125; 52⋅2=505^2\cdot2 = 50; 52⋅3=755^2\cdot3 = 75; 22⋅5=202^2\cdot5 = 20; 32⋅5=453^2\cdot5 = 45. The smallest is 20\mathbf{20}, with divisors 1,2,4,5,10,201, 2, 4, 5, 10, 20.