/* ==================================================================== */ void Eratosthenes(BitArray_t arr) { SetBit(arr, 0, 1); SetBit(arr, 1, 1); size_t i_stop = ceil(sqrt(BitArraySize(arr))); for (size_t i = 2; i <= i_stop; ++i) { if (!GetBit(arr, i)) { for (size_t ii = 2 * i; ii < BitArraySize(arr); ii += i) { SetBit(arr, ii, 1); } } } }
static void Eratosthenes(BitArray_t pole) { unsigned long long i,n; for (i = 2; i<= sqrt(BitArraySize(pole)) ; i++) // od 2 do sqrt(N) { if (GetBit(pole,i) == 0) for (n = 2; n*i <= (BitArraySize(pole)); n++) { SetBit(pole, i*n,1); // "vyskrta nasobky prvocisla" } } return; }
void Eratosthenes(BitArray_t pole) { double upToSqrt = sqrt(BitArraySize(pole)); for(int j = 2; j < upToSqrt; ++j) { if(GetBit(pole, j) == 0) { for(int i = j*2; i < BitArraySize(pole); i += j) { SetBit(pole, i, 1); } } } }
/* * Set 0 on primary bits in given BitArray via Eatosthenes algorithm * * @param pole BitArray on which */ void Eratosthenes(BitArray_t pole) { unsigned long N = BitArraySize(pole); double limit = sqrt(N); for(unsigned long i = 2; i < limit; i++) { if(GetBit(pole,i) == 0) { for(unsigned long n = 2; n*i < N; n++) { SetBit(pole,n*i,1); } } } }