Пример #1
0
 public PrimeSieve2(long upTo)
 {
     primes = new GrowableArray<bool>(upTo);
     primes.Set(0, true);
     primes.Set(1, true);
     PopulateSieveFrom(primes);
 }
Пример #2
0
 public void TestArrayAccess()
 {
     int sz = 100;
     GrowableArray<int> ga = new GrowableArray<int>(sz);
     for(int i = 0; i < 2 * sz; ++i)
     {
         ga.Set(i, 13*i);
         Assert.AreEqual(i < sz ? sz : 2 * sz, ga.LongLength);
     }
     for(int i = 0; i < 2 * sz; ++i)
     {
         Assert.AreEqual(i*13, ga.Get(i));
     }
 }
Пример #3
0
 private static void PopulateSieveFrom(GrowableArray<bool> sieve, long from = 2)
 {
     long upTo = (long)Math.Sqrt(sieve.LongLength) + 1;
     for (long i = 2; i < upTo; i++)
     {
         if (!sieve.Get(i))
         {
             var k = (i < from) ? FirstK(i, from) : 2 * i;
             while (k < sieve.LongLength)
             {
                 sieve.Set(k,true);
                 k += i;
             }
         }
     }
 }