Sub topic 6
Prime Factorization and the Factor Tree
Assume you can multiply, divide, use exponent notation, and identify factors and prime numbers. This chapter shows how to break a positive integer into its prime building blocks. That process is called prime factorization.
What prime factorization means
A prime number has exactly two positive factors: 1 and itself. Examples include 2, 3, 5, 7, and 11. A composite number has more than two positive factors.
The prime factorization of an integer writes it as a product of primes. For example,
\[ 60=2\cdot2\cdot3\cdot5=2^2\cdot3\cdot5. \]
The second form is usually more useful because exponents show repeated factors. Every integer greater than 1 has exactly one prime factorization, apart from the order of the factors.
The number 1 is neither prime nor composite. Its prime factorization is considered an empty product, so it contributes no prime factors.
Building a factor tree
A factor tree repeatedly splits a composite number into two factors. Continue splitting until every final branch is prime.
For 360, one possible tree is:
Reading the leaves gives
\[ 360=2\cdot2\cdot3\cdot3\cdot2\cdot5=2^3\cdot3^2\cdot5. \]
The first split does not matter. For example, splitting 360 into 18 and 20 leads to the same final primes.
A reliable factoring method
Start with the smallest prime, 2. Divide while the number is even. Then test 3, 5, 7, and later primes until the remaining value is 1.
For example:
\[ 360\div2=180,\qquad 180\div2=90,\qquad 90\div2=45. \]
Then,
\[ 45\div3=15,\qquad 15\div3=5. \]
The remaining 5 is prime, so
\[ 360=2^3\cdot3^2\cdot5. \]
You only need to test possible prime divisors up to the square root of the current number. If no such prime divides the number, the current number is prime.
def prime_factors(n):
factors = {}
p = 2
while p * p <= n:
while n % p == 0:
factors[p] = factors.get(p, 0) + 1
n //= p
p += 1
if n > 1:
factors[n] = factors.get(n, 0) + 1
return factors
print(prime_factors(360)) # {2: 3, 3: 2, 5: 1}Common errors and GRE use
Do not stop when a factor is merely odd or small. Stop only when every factor is prime. Also check the result by multiplying the prime powers back together.
Prime factorization is useful beyond factoring itself. It lets you count divisors, find the greatest common divisor and least common multiple, and identify whether an integer is a perfect square. In GRE questions, factor the smaller or more structured number first, and use divisibility rules before trial division.
Exercise
Find the prime factorization of 252.
Show answer
252 = 2^2 · 3^2 · 7.