Kajang

The screen of Ératosthène is a process which makes it possible to find all the prime numbers lower than some Entier naturalness given NR . It is the ancestor of most recent the Crible of Atkin which is faster but more complex.

Algorithm

One forms a table with all the natural entireties ranging between 2 and NR and one raye the ones after the others, the entireties which are not first in the following way: as soon as one finds an entirety which was not striped yet, he is declared first, and one raye all the other multiples of this one.

Let us study an example for the entireties lower than 120:

Let us determine the list of all step by step the prime numbers lower than 20:

Stage 1. Let us write the list of the natural numbers ranging between 2 and 20

Stage 2. One marks the following number not striped list, like first.

Stage 3. One raye in the list, all multiples of the number which one has just surrounded.

Stage 4. If the square of the following number not striped is lower than 20, then one starts again at stage 2 if not one declares all the entireties remaining not striped first.

Since 3 high squared is lower than 20, one turns over at stage 2:

At stage 4, the following entirety not striped 5 has a square strictly higher than 20, one regards as first all the not striped following entireties.

Result: The entireties first ranging between 2 and 20 are: 2,3,5,7,11,13,17,19.

To obtain to entireties first lower than N=99, one raye in the order all multiples of the prime numbers p=2, 3,5,7,… starting from p^2 until NR. One stops when the entirety first p following checks p^2>N (If an entirety not first is strictly higher than \ sqrt {NR} then it has at least a divider lower than \ sqrt {NR} and is thus already striped). One thus will go until p=9, because 102=100>99, and will declare first all the following not striped entireties. The following table is obtained:

The screen of Eratosthène coded out of C

Here what the screen of Eratosthène coded out of C gives (only the function which makes it possible to calculate the prime numbers is posted here)
  • Remarque: table " tableau" integers (between 2 and NR) must be created and filled before the use of this function

1 void first (length table, length tailleTableau) 2 { 3 int I = 0, there = 0; 4 long divider = 0; 5 6 7 for (I = 0; I < sqrt (tailleTableau); i++) 8 { 9 yew (table! = 0) 10 { 11 divider = table; 12 13 for (there = (i+1); there < tailleTableau; there ++) 14 yew ((tableau%divisor) == 0) 15 table = 0; 16 17} 18} 19 20 21 for (I = 0; I < tailleTableau; i++) 22 yew (table! = 0) 23 printf (" %ld " , table); 24}

  • Lines 3 to 4: Declaration of the variables necessary (" i" and " y" to traverse table " tableau" and " diviseur" to test if a number is first or not).

  • Line 9: It is checked if one did not already remove the number, if it is not the case one continues, if not, one passes to the following number.
  • Line 11: One associates with the variable " diviseur" the value of the number present at the site " y" table " tableau".
  • Lines 13 to 16: It is looked at if the numbers which follow the initial site d'" y" divided by " diviseur" form a null remainder or not. If they form a null remainder, they are not first, one them raye.
  • Lines 21 to 23: If the number located at the site " y" table " tableau" is not striped (equal to zero), one posts it.

Random links:Popular movement of the Revolution | Canton of Londinières | Sansetsukon | Al-Akhtal (crater) | Born Again (album of The Notorious B.I.G.) | Kajang