Sub topic 7
Factor pairs, perfect squares and odd factor counts
This chapter assumes you can write a number in prime-power form, such as 360 = 2³ × 3² × 5, and that you know the formula for the number of factors, d(n) = (e₁ + 1)(e₂ + 1)…. Here you will use that formula to see why factors pair up, why only perfect squares have an odd number of factors, and how CAT turns this into counting questions.
Factors come in pairs
If d divides n, then n/d also divides n. So every factor has a partner, and the two multiply to n. For 36:
| Smaller factor | Partner | Product |
|---|---|---|
| 1 | 36 | 36 |
| 2 | 18 | 36 |
| 3 | 12 | 36 |
| 4 | 9 | 36 |
| 6 | 6 | 36 |
The smaller member of each pair is at most √n, and the larger is at least √n. This gives a practical search rule. To list all factors of n, test divisors only up to √n and write down each partner as you go. For 360, √360 is about 18.97, so you test 1 to 18 and get 12 pairs.
Why only perfect squares have an odd factor count
Normally a factor and its partner are different numbers, so factors are counted two at a time. The count becomes odd only when some factor is its own partner. That happens when d = n/d, which means d² = n. So n must be a perfect square, and the self-paired factor is √n.
The prime-exponent formula gives the same result. The count is d(n) = (e₁ + 1)(e₂ + 1)…(eₖ + 1). A product is odd only if every term is odd, so every (eᵢ + 1) must be odd, so every eᵢ must be even. A number whose prime exponents are all even is exactly a perfect square.
The result runs in both directions:
- A perfect square has an odd number of factors.
- A number with an odd number of factors is a perfect square.
- A number that is not a perfect square has an even number of factors.
The number 1 is a perfect square (1 = 1²). It has exactly one factor, which is its own partner.
Counting ways to split a number into two factors
The wording of the question decides which count you need.
- Ordered pairs (a, b) with a × b = n: the answer is d(n). Here (4, 9) and (9, 4) count as different.
- Unordered pairs: the answer is d(n)/2 when n is not a perfect square. When n is a perfect square, the answer is (d(n) + 1)/2, because the pair (√n, √n) is counted only once.
For 36, d = 9, so there are 9 ordered pairs and (9 + 1)/2 = 5 unordered pairs, matching the table above. For 360, d = 24, so there are 12 unordered pairs.
A related count is the number of ways to split n into two coprime factors, meaning factors with no common prime. Each prime power must go entirely to one side. If n has k distinct primes, each prime picks a side, giving 2ᵏ ordered splits and 2ᵏ⁻¹ unordered splits. For 360 = 2³ × 3² × 5, k = 3, so there are 4 unordered coprime splits: (1, 360), (8, 45), (9, 40) and (5, 72). The exponents do not matter here. Only the number of distinct primes does.
Product of all factors
Pairing also gives the product of all factors. Each pair multiplies to n, and there are d(n)/2 pairs, so
product of all factors = n^(d(n)/2)
This formula works for perfect squares too. The self-paired factor √n contributes n^(1/2), which is half a pair. For 36 the product is 36^(9/2) = 6⁹ = 10,077,696.
Perfect-square factors and making a number square
To count the factors of n that are themselves perfect squares, note that such a factor uses an even power of each prime. A prime with exponent e in n can appear in the factor with exponents 0, 2, 4, …, up to e. That gives ⌊e/2⌋ + 1 choices. Multiply over all primes:
square factors of n = ∏ (⌊eᵢ/2⌋ + 1)
For 360 = 2³ × 3² × 5¹ the count is (1 + 1)(1 + 1)(0 + 1) = 4. The factors are 1, 4, 9 and 36.
To make n a perfect square, look at the primes with an odd exponent.
- The smallest number to multiply by is the product of those primes. For 360 the odd-exponent primes are 2 and 5, so multiply by 10 to get 3600 = 60².
- The smallest number to divide by is the same product. 360 / 10 = 36 = 6².
For a perfect cube the same idea applies with exponents that are multiples of 3.
Checking the rules in code
This program verifies the odd-count rule by brute force for every n from 1 to 500. It also lists factor pairs and counts square factors.
from math import isqrt
def divisors(n):
return [d for d in range(1, n + 1) if n % d == 0]
def factor_pairs(n):
return [(d, n // d) for d in range(1, isqrt(n) + 1) if n % d == 0]
def square_factor_count(n):
return sum(1 for d in divisors(n) if isqrt(d) ** 2 == d)
print(factor_pairs(36))
print(len(factor_pairs(360)))
print(square_factor_count(360))
print(all(
(len(divisors(n)) % 2 == 1) == (isqrt(n) ** 2 == n)
for n in range(1, 501)
))The output is:
[(1, 36), (2, 18), (3, 12), (4, 9), (6, 6)]
12
4
TrueClassic CAT patterns
The locker problem. One hundred lockers are all closed. Student 1 toggles every locker, student 2 toggles every second locker, student 3 every third, and so on up to student 100. Which lockers end up open? Locker k is toggled once for each factor of k. It ends open only if it was toggled an odd number of times, so k must be a perfect square. The open lockers are 1, 4, 9, …, 100, which is 10 lockers. The same reasoning applies to light-switch and coin-flipping puzzles.
Exactly three factors. If d(n) = 3, then 3 = (e + 1) means n = p² for a prime p. For numbers up to 100, these are 4, 9, 25 and 49, so there are 4 of them.
Exactly two factors. This is a prime. The count d(n) = 2 means n = p¹.
Working backwards from a count. If d(n) = 15, the exponent patterns are 14 (n = p¹⁴) or (4, 2) (n = p⁴q²). Both give odd counts, so n is a perfect square, which checks out. List the factorizations of the count to list the possible shapes of n.
Common errors
- Counting the pair (√n, √n) twice when listing unordered pairs of a perfect square.
- Using d(n)/2 for a square, which gives a fraction.
- Forgetting that 1 and n are factors, so a prime has 2 factors, not 0.
- Writing ⌊e/2⌋ without adding 1 when counting square factors, which drops the choice of exponent 0.
- Assuming "odd factor count" means "odd number". The number 36 is even and has 9 factors.
Exercise
How many factors of 1800 are perfect squares, and what is the smallest positive integer you must multiply 1800 by to get a perfect square?
Show answer
1800 = 2³ × 3² × 5². Square factors: (⌊3/2⌋ + 1)(⌊2/2⌋ + 1)(⌊2/2⌋ + 1) = 2 × 2 × 2 = 8. The only odd exponent is on 2, so multiply by 2 to get 3600 = 60².
Exercise
The number N = 2⁴ × 3² × 7 has how many ordered pairs (a, b) of positive integers with a × b = N, and how many of those pairs have a and b coprime and a < b?
Show answer
d(N) = 5 × 3 × 2 = 30, so there are 30 ordered pairs. N has 3 distinct primes, so there are 2³ = 8 ordered coprime splits. Because N is not a perfect square, a ≠ b in every split, so exactly half have a < b, which is 4.