Check every number
Divisors by checking every number
Where can divisors be?
Any divisor of 375 must lie between 1 and 375.
What is the simplest sure way to find all the divisors of 375?
What this lesson covers
The idea
To list the divisors of n, check each j from 1 to n and add j to the list if j divides n.
Where can divisors be?
Any divisor of 375 must lie between 1 and 375.
What is the simplest sure way to find all the divisors of 375?
- Check each number from 1 to 375
- Check only the odd numbers below 20
- Divide 375 by 2 again and again
Run it for 375
The book's algorithm: 1. Start with an empty list-of-divisors. 2. For each number j in the sequence 1, 2, 3, …, n: if j divides n, add j to the list-of-divisors. Run it for n = 375.
Check them all
To list the divisors of n, check each j from 1 to n, and add j to the list if j divides n.
For 375 the algorithm makes 375 checks and finds divisors(375) = [1, 3, 5, 15, 25, 75, 125, 375]. The basic step we assume: we know how to tell whether a smaller number divides a larger number.
Notes
divisors(n): start with an empty list; for each j = 1, 2, 3, …, n, if j divides n, add j to the list. It makes n checks.
Check yourself
How many numbers does the algorithm check to find divisors(825)?
Answer: 825
j goes from 1 to 825, so 825 checks.
What basic step does this algorithm assume we can do?
Execute the algorithm for 15. What is divisors(15)?
- Tell whether a smaller number divides a larger number — correct. Yes, that is the book's answer.
- Find the gcd of two numbers. That is what we are building towards, not a basic step.
- Add two single digits. That was the basic step of the addition algorithm.
- [1, 3, 5, 15] — correct. Yes. 1, 3, 5 and 15 divide 15; the others do not.
- [3, 5]. 1 and 15 also divide 15.
- [1, 2, 3, 4, 5, 15]. 2 and 4 do not divide 15.