optimized algorithm
authorChristoph Fuerst <ch.fuerst@gmx.at>
Fri, 14 Apr 2017 16:36:05 +0000 (18:36 +0200)
committerChristoph Fuerst <ch.fuerst@gmx.at>
Fri, 14 Apr 2017 16:36:05 +0000 (18:36 +0200)
sieveEratosthenes.txt

index 4790088..0ae53d4 100644 (file)
@@ -40,10 +40,9 @@ proc SieveOfErathostenes(m:nat): Array[MAX,Bool]
    {
          if ret[i] = true then
          {
-             j = i^2;
             for k=0;i^2+k*i<MAX;k=k+1 do
             {
-                j=i^2+k*i;
+            j=i^2+k*i;
                ret[j] = false;
             }
          }
@@ -82,3 +81,4 @@ proc SieveOfErathostenesSet(m:ℕ[MAX]): Set[ℕ[MAX]]
    return ret;
 }
 
+