Hallo,
also ich bin hier mit 0,37 sec dabei mit dem guten alten Erastosthenes...
Hier mal als Java Vorlage, kannst ja mal für VBA umschreiben, wenn Du schon was üben mußt...hehe....
public class Sieb {
public static void main (String argv[]) {
boolean[] sieb; // boole’sches Array
int i, j, n; // Laufvariablen
n = IO.readInt("Bitte Primzahlgrenze: "); // fordere Obergrenze an
sieb = new boolean[n]; // allokiere Speicherplatz
for (i = 2; i < n; i++) sieb[i] = true; // alle sind zunaechst Primzahl
for (i = 2; i < n; i++)
if (sieb[i]) { // falls i als Primzahl erkannt,
IO.print(i,6); // gib sie aus, und
for (j = i+i; j < n; j += i) // fuer alle Vielfachen j von i
sieb[j] = false; // streiche j aus der Liste
}
}
}
...Und naja in der ein oder anderen Form findet man Deinen Code nat schon im Netz, aber ok etwas umformen is auch schonmal gut..;-)
https://www.wbrnet.info/db/0043.html
Gruß,
|