Sub topic 5
Primes and Composites
Assume you know basic integer arithmetic, negative numbers, zero, and exponent notation. This chapter focuses on recognizing prime and composite integers and testing whether a number has a factor.
Definitions and edge cases
A factor of an integer is an integer that divides it evenly. For example, 3 is a factor of 12 because 12 ÷ 3 = 4. The positive factors of 12 are 1, 2, 3, 4, 6, and 12.
A prime number is a positive integer greater than 1 with exactly two positive factors: 1 and itself. The first primes are 2, 3, 5, 7, 11, and 13.
A composite number is a positive integer greater than 1 that has more than two positive factors. For example, 12 is composite because it has six positive factors.
The numbers 0 and 1 are neither prime nor composite. Negative integers are also not classified as prime or composite in standard GRE questions.
| Number | Classification | Reason |
|---|---|---|
| 2 | Prime | Factors are 1 and 2 |
| 9 | Composite | Factors include 1, 3, and 9 |
| 1 | Neither | It has only one positive factor |
| 0 | Neither | Division by zero is undefined |
How to test whether a number is prime
To determine whether n is prime, test whether any integer from 2 through the square root of n divides n evenly. If none does, n is prime.
Why stop at the square root? If n = ab and both a and b were greater than the square root of n, then ab would be greater than n. Therefore, every factor pair has at least one factor at or below the square root.
For example, to test 29, check divisibility by 2, 3, and 5 because the square root of 29 is a little more than 5. None divides 29, so 29 is prime.
To test 91, check 2, 3, 5, and 7. Since 91 = 7 × 13, it is composite. You do not need to test 11 or larger numbers.
from math import isqrt
def is_prime(n):
if n < 2:
return False
for divisor in range(2, isqrt(n) + 1):
if n % divisor == 0:
return False
return True
for number in [1, 2, 29, 91]:
print(number, is_prime(number))GRE patterns and common errors
Every integer greater than 1 is either prime or composite. A composite number can be written as a product of smaller positive integers.
The number 2 is the only even prime. Every other even integer is composite because it has 2 as a factor.
A number ending in 0 or 5 is composite when it is greater than 5. A number whose digit sum is divisible by 3 is composite unless the number is 3 itself. These quick tests often eliminate choices without complete factorization.
Exercise
Is 97 prime? Explain the shortest reliable test.
Show answer
Yes. Test 2, 3, 5, and 7, the integers no greater than the square root of 97. None divides 97 evenly, so 97 is prime.