MathCompass

Divisibility & Prime Numbers

Number Theory Intermediate

πŸ“‹ Prerequisites

Number theory starts with divisibility and primes β€” the atoms of the integer world. Know the divisibility rules, understand what makes a number prime, and master the Sieve of Eratosthenes. These are the foundation for everything else in number theory: GCD, LCM, modular arithmetic, and beyond.

πŸ“š Key Concepts

Divisibility Definition

An integer $a$ is divisible by a nonzero integer $b$ if there exists an integer $k$ such that $a = b \cdot k$.

Notation: $ b \mid a $ (read "b divides a")

Examples: $ 3 \mid 12 $ because 12 = 3 \(\times\) 4. $ 5 \nmid 12 $ because 12 isn't a multiple of 5.

Properties:

Divisibility Rules

Why these work: \(Because 10 \\equiv 0 mod 2,5; 10 \\equiv 1 mod 3,9; 10 \\equiv -1 mod 11. We'll prove this properly with modular arithmetic later.\)

Prime & Composite Numbers

A positive integer greater than 1 is:

Important notes:

Sieve of Eratosthenes

An efficient algorithm to find all primes up to a given number n:

  1. Write all numbers from 2 to n
  2. Start with the smallest prime (2), mark all its multiples as composite
  3. Move to the next unmarked number β€” it's prime. Mark all its multiples
  4. Continue until you pass $\sqrt{n}$
  5. All remaining unmarked numbers are prime

Optimization: you only need to check up to $\sqrt{n}$ because any composite n must have a factor \(\leq \sqrt{n}.\)

Prime Factorization

Every positive integer can be written uniquely as a product of primes (up to ordering).

This is the Fundamental Theorem of Arithmetic.

Example: $ 84 = 2^2 \times 3 \times 7 $

How to factor: divide by small primes repeatedly, or use factor trees.

Euclid's Lemma

If a prime $p$ divides the product $ab$, then $p$ divides $a$ or $p$ divides $b$ (or both).

This is why primes are "atomic" β€” they can't be split across factors. If a prime shows up in a product, it must come entirely from one factor or the other.

\(Important: this only works for primes! Composite numbers don't have this property (e.g., 6 divides 4 \\times 3 but 6 doesn't divide 4 or 3 individually).\)

Counting Divisors (Preview)

If $ n = p_1^{a_1} \cdot p_2^{a_2} \cdot ... \cdot p_k^{a_k} $, then the number of positive divisors is:

\[ d(n) = (a_1 + 1)(a_2 + 1)...(a_k + 1) \]

Because for each prime, you can choose exponent 0 through $a_i$ in the divisor. We'll cover this more in the GCD/LCM module.

⚠️ Common Mistake: 1 is NOT prime! It's neither prime nor composite. This trips up a lot of people. Also: the divisibility rule for 3 uses the digit sum, but the rule for 11 uses the alternating sum (add-subtract-add-subtract...). Don't mix them up. And remember: to check if n is prime, you only need to test divisibility by primes up to $\sqrt{n}$, not all the way to n.
πŸ’‘ Key Insight: When a problem asks "how many divisors?" or "is this divisible by that?", the first move is almost always prime factorization. Break every number down to primes, then everything becomes counting exponents. The Fundamental Theorem of Arithmetic is your superpower β€” every integer has a unique "prime fingerprint," and comparing fingerprints tells you everything about divisibility, GCD, LCM, and more.

✏️ Example Problems

πŸ“ Example 1 (Divisibility rule for 3)

Is 1,236 divisible by 3? Answer 1 for yes, 0 for no.

Divisibility by 3: sum the digits, check if divisible by 3.

Step 1: Sum the digits of 1,236.

1 + 2 + 3 + 6 = 12

Step 2: Is 12 divisible by 3?

12 Γ· 3 = 4, which is an integer. Yes!

Step 3: Verify: 1,236 Γ· 3 = 412. βœ“

Answer: 1 (yes)

πŸ“ Example 2 (Prime factorization)

What is the prime factorization of 180?
Express as $2^a \times 3^b \times 5^c$. What is $a + b + c$?

Step 1: Divide by smallest prime (2) repeatedly.

180 Γ· 2 = 90

90 Γ· 2 = 45

45 is odd β€” can't divide by 2 anymore. Got $2^2$.

Step 2: Next prime (3).

45 Γ· 3 = 15

15 Γ· 3 = 5

Got $3^2$.

Step 3: Next prime (5).

5 Γ· 5 = 1

Got $5^1$.

Step 4: Write it out.

\[ 180 = 2^2 \times 3^2 \times 5^1 \]

a = 2, b = 2, c = 1

a + b + c = 2 + 2 + 1 = 5

Answer: 5

πŸ“ Example 3 (How many primes between 1 and 30?)

How many prime numbers are there between 1 and 30 inclusive?

Use Sieve of Eratosthenes thinking.

\((\sqrt{30} \\approx\) 5.5, so we only need to check primes 2, 3, and 5.\)

Step 1: List numbers 1-30, mark composites.

Start with 2: mark 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30

Next prime 3: mark 6, 9, 12, 15, 18, 21, 24, 27, 30

Next prime 5: mark 10, 15, 20, 25, 30

\(We're done (next prime is 7, and 7 > \sqrt{30}).\)

Step 2: Count unmarked numbers (primes).

2, 3, 5, 7, 11, 13, 17, 19, 23, 29

That's 10 primes.

Note: 1 is not prime.

Answer: 10

Start of Track
Next