Sub topic 7
Counting the Factors of an Integer
This chapter assumes you can write the prime factorization of an integer, read exponent notation such as 2^3, and tell a factor from a multiple. If prime factorization is still shaky, review it first. Every step below depends on it.
By the end you will be able to count the positive factors of an integer without listing them. You will also see where students lose points on this topic and how GRE questions use it.
Why listing factors is not enough
You can find the factors of 360 by testing every number from 1 up to 360. That is slow and easy to get wrong. The GRE usually asks only how many factors there are, or compares two such counts. A short formula answers that from the prime factorization.
In this chapter, "factor" means "positive factor" unless a problem says otherwise. Factors of 12 are 1, 2, 3, 4, 6, and 12. If a problem asks for all integer divisors, the negatives come too, and the count doubles.
The building-block idea
Take 360 = 2^3 × 3^2 × 5. Any divisor of 360 is made only from the primes 2, 3, and 5. It cannot use more copies of a prime than 360 has. So you build a divisor by making three independent choices:
- The exponent of 2 can be 0, 1, 2, or 3. That is 4 choices.
- The exponent of 3 can be 0, 1, or 2. That is 3 choices.
- The exponent of 5 can be 0 or 1. That is 2 choices.
Each combination of choices gives a different divisor, and every divisor arises from exactly one combination. Choosing exponents (2, 1, 0) gives 2^2 × 3^1 × 5^0 = 12. Choosing (0, 0, 0) gives 1. Choosing (3, 2, 1) gives 360 itself. The total is 4 × 3 × 2 = 24.
The formula
If n = p1^a1 × p2^a2 × ... × pk^ak, where the p's are distinct primes, then the number of positive divisors is
(a1 + 1)(a2 + 1)...(ak + 1)
Add 1 to each exponent, then multiply. The "+1" counts the choice of exponent 0, which means "leave this prime out."
Special cases follow directly:
- A prime p = p^1 has 1 + 1 = 2 divisors: 1 and p.
- A prime power p^k has k + 1 divisors: 1, p, p^2, ..., p^k.
- The number 1 has an empty factorization and exactly 1 divisor, itself.
- A product of k distinct primes has 2^k divisors, because each prime is either in or out.
Checking the formula in code
This script builds the prime factorization by trial division, applies the formula, and compares it with a brute-force count.
from math import prod
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
def count_divisors(n):
return prod(e + 1 for e in prime_factors(n).values())
def brute_force_count(n):
return sum(1 for d in range(1, n + 1) if n % d == 0)
for n in (1, 7, 60, 72, 100, 360):
print(n, count_divisors(n), brute_force_count(n))The two counts agree on every line: 1 → 1, 7 → 2, 60 → 12, 72 → 12, 100 → 9, 360 → 24. For 1, the factorization is empty and prod of an empty sequence is 1, which is correct.
Worked examples
| n | Prime factorization | Exponents + 1 | Divisors |
|---|---|---|---|
| 12 | 2^2 × 3 | 3 × 2 | 6 |
| 36 | 2^2 × 3^2 | 3 × 3 | 9 |
| 48 | 2^4 × 3 | 5 × 2 | 10 |
| 97 | 97 (prime) | 2 | 2 |
| 1000 | 2^3 × 5^3 | 4 × 4 | 16 |
Expressions that are not yet in prime form
The formula needs primes as bases. For 12^2, the exponent is 2, but 12 is not prime. Factor first: 12^2 = (2^2 × 3)^2 = 2^4 × 3^2. The count is 5 × 3 = 15, not 3.
The same applies to 6^4 = 2^4 × 3^4. It has 5 × 5 = 25 divisors.
Restricted counts
Questions often ask for only some divisors. Remove or fix primes before you multiply.
- Odd divisors of 360. An odd divisor uses no 2, so the exponent of 2 is fixed at 0. Count with 3^2 × 5 only: 3 × 2 = 6.
- Even divisors of 360. Subtract the odd ones from all of them: 24 − 6 = 18.
- Divisors of 360 that are multiples of 6. A divisor d is a multiple of 6 when d = 6m, and then m divides 360/6 = 60. So count the divisors of 60 = 2^2 × 3 × 5: 3 × 2 × 2 = 12.
- Divisors of 360 that are multiples of 5. Write d = 5m, where m divides 72 = 2^3 × 3^2. The count is 4 × 3 = 12.
The general move is to fix the required part, divide it out, and count what is left.
Factor pairs
Divisors come in pairs (d, n/d) whose product is n. For 360, the 24 divisors form 12 pairs, such as (1, 360), (2, 180), and (18, 20). A number has an odd count of divisors only when some divisor pairs with itself, which happens only for perfect squares. The next chapter takes that up.
Using the count on the GRE
Quantitative comparison
A bigger number does not have more divisors. Compare these:
- Quantity A: the number of positive divisors of 72.
- Quantity B: the number of positive divisors of 60.
Since 72 = 2^3 × 3^2 and 60 = 2^2 × 3 × 5, Quantity A is 4 × 3 = 12 and Quantity B is 3 × 2 × 2 = 12. The quantities are equal.
Compare 64 and 60 as well. Since 64 = 2^6 has only 7 divisors while 60 has 12, the smaller number wins. Numbers built from many small primes tend to have the most divisors.
Working backward from the count
Some questions give the count and ask about the number.
- Exactly 2 divisors means n is prime.
- Exactly 3 divisors means n = p^2 for a prime p, because 3 can only be written as 2 + 1.
- Exactly 12 divisors: 12 can be factored as 12, 6 × 2, 4 × 3, or 3 × 2 × 2. Subtracting 1 from each factor gives exponent patterns. The smallest number comes from putting the largest exponents on the smallest primes:
| Exponent pattern | Smallest number |
|---|---|
| (11) | 2^11 = 2048 |
| (5, 1) | 2^5 × 3 = 96 |
| (3, 2) | 2^3 × 3^2 = 72 |
| (2, 1, 1) | 2^2 × 3 × 5 = 60 |
The smallest positive integer with exactly 12 divisors is therefore 60. You can confirm it by search.
from itertools import count
from math import prod
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
def count_divisors(n):
return prod(e + 1 for e in prime_factors(n).values())
print(next(n for n in count(1) if count_divisors(n) == 12)) # 60Common errors
- Forgetting the +1. Multiplying the exponents (3 × 2 × 1 = 6 for 360) ignores the exponent-0 choice. The correct count is 24.
- Dropping 1 and n. Both are divisors. If a problem says "factors other than 1 and itself," subtract 2 from the count.
- Counting distinct prime factors instead. 360 has 3 distinct prime factors (2, 3, 5), but 24 divisors. These are different questions.
- Applying the formula to a non-prime base. Always rewrite the number in primes first, as with 12^2.
- Repeating a prime. If your factorization lists 2 twice, as in 2^3 × 2 × 3, combine it into 2^4 × 3 before counting.
- Ignoring negatives when the problem says "integer divisors." Double the count in that case.
Exercises
Exercise
How many positive divisors does 2520 have? (Hint: 2520 = 2^3 × 3^2 × 5 × 7.)
Show answer
Add 1 to each exponent and multiply: (3 + 1)(2 + 1)(1 + 1)(1 + 1) = 4 × 3 × 2 × 2 = 48.
Exercise
How many positive divisors of 360 are odd multiples of 3?
Show answer
Write 360 = 2^3 × 3^2 × 5. An odd divisor uses 2^0. A multiple of 3 needs the exponent of 3 to be 1 or 2, which is 2 choices. The exponent of 5 has 2 choices. The count is 1 × 2 × 2 = 4. They are 3, 9, 15, and 45.
Exercise
Quantity A is the number of positive divisors of 100. Quantity B is the number of positive divisors of 96. Which is greater, or are they equal?
Show answer
Since 100 = 2^2 × 5^2, it has 3 × 3 = 9 divisors. Since 96 = 2^5 × 3, it has 6 × 2 = 12 divisors. Quantity B is greater, even though 96 is smaller than 100.
Exercise
A positive integer n has exactly 3 positive divisors, and n is less than 50. What are the possible values of n?
Show answer
A number with exactly 3 divisors has the form p^2 for a prime p. The squares of primes below 50 are 4, 9, 25, and 49, so n is one of these.