Sieve of Eratosthenes is actually a straightforward algorithm based on the definition of prime numbers:
1. Mark all integers that greater than 1 as primes.
2. Take the smallest prime that is not already considered and cross out all its multiples.
3. Repeat 2nd step for the next prime.
The above Python code that returns all primes number less than a given limit uses two optimization:
1. Repeat 2nd step upto sqrt(limit), not upto limit.
2. Start crossing out at the square of the prime, not at twice of the prime.
The only “intuitive” interface is the nipple. After that, it’s all learned.http://news.ycombinator.com/item?id=409288 (It might be not true literally but the quote is useful as a general idea that people have different backgrounds; an “intuitive” thing for one person is a cryptic for another. Intuitiveness changes with experience.)
1. Mark all integers that greater than 1 as primes. 2. Take the smallest prime that is not already considered and cross out all its multiples. 3. Repeat 2nd step for the next prime.
The above Python code that returns all primes number less than a given limit uses two optimization:
1. Repeat 2nd step upto sqrt(limit), not upto limit. 2. Start crossing out at the square of the prime, not at twice of the prime.
The only “intuitive” interface is the nipple. After that, it’s all learned. http://news.ycombinator.com/item?id=409288 (It might be not true literally but the quote is useful as a general idea that people have different backgrounds; an “intuitive” thing for one person is a cryptic for another. Intuitiveness changes with experience.)