
Primes = primes /** get rid of excess storage space **/ Primes = list /** put them at the end of the list **/

** include remaining numbers greater than sqrt(max) **/ P = list /** next prime number to sift **/

Primes = p /** include p in the list of primes **/ List = remove(list, idx) /** remove them. Idx = loc( mod(list, p)=0 ) /** find all numbers divisible by p **/ P = list /** 2 is the first prime **/ĭo while (p#2 <= max) /** search through sqrt(max) **/ List = 2:max /** find prime numbers in **/ In celebration of Riemann’s birthday, I present the Sieve of Eratosthenes in the SAS/IML language: It is the only algorithm that I know of that has a poem written about it:

One of the first mathematical algorithms that I learned as a kid is the “prime number sieve." (There is an animation of this algorithm in the Wikipedia article.) This algorithm is attributed toĮratosthenes, a mathematician from ancient Greece, and has been implemented in many programming languages. In honor of Riemann's birthday, this post deals with prime numbers. Riemann is definitely on my list of the greatest mathematicians of all time, and his conjecture about the distribution of prime numbers is one of the great unsolved problems in mathematics. Today is the birthday of Bernhard Riemann, a German mathematician who made fundamental contributions to the fields of geometry, analysis, and number theory.
