Generate and Test (cont)
Simple example: checking whether an integer n is prime
- generate/test all possible factors of n
- if none of them pass the test ⇒ n is prime
Generation is straightforward:
- produce a sequence of all numbers from 2 to n-1
Testing is also straightforward:
- check whether next number divides n exactly
|