private void NextPrime()
        {
            int p = primes[primes.Count - 1] + 1;

            while (p < m + n && bits[p - m])
            {
                ++p;
            }
            if (p == m + n)
            {
                if (m > maximumSize)
                {
                    throw new InvalidOperationException("too many primes");
                }
                m   += n;
                n   *= 2;
                bits = new Word64BitArray(n);
                for (int i = 0; i < primes.Count; i++)
                {
                    Sieve(primes[i]);
                }
                while (p < m + n && bits[p - m])
                {
                    ++p;
                }
            }
            Sieve(p);
            primes.Add(p);
        }
 public SieveOfEratosthenes()
 {
     bits    = new Word64BitArray(initialSize);
     bits[0] = true;
     bits[1] = true;
     m       = 0;
     n       = initialSize;
     primes  = new List <int>();
     primes.Add(2);
     Sieve(2);
 }