On the following address you can find a good example on how the Sieve of Eratosthenes works on the first 100 numbers.
http://en.wikipedia.org/wiki/File:Animation_Sieve_of_Eratosth-2.gif
Brief Explanation of the picture:
1. Take the first number (2), it has 2 divisors - 1 and 2 itself. So mark all the numbers that divide by 2 (the red color).
2. Take the next number (3), that is not marked by the previous step (number 3). It has 2 divisors - 1 and 3 itself, mark all the numbers that divide by 3 (green color).
3. Take the next number that is not marked by the previous steps and check if it had exactly two divisors - 1 and the number itself (the chance this number to be prime number is bigger as all the numbers that may be divisors to this number are already marked). Mark all the numbers that divide by the number choosen.
4. Repeat step 3 until the number choosen is less than or equal to the limit you want to find the prime numbers for.
Note : I would like to excuse for my poor scientific english :).
1 comment:
hello... hapi blogging... have a nice day! just visiting here....
Post a Comment