Sieve of Eratosthenes: Difference between revisions
Content deleted Content added
Improve C++ style for stdlib version. |
m Fix bug in recent edit. |
||
Line 2,794: | Line 2,794: | ||
{ |
{ |
||
auto prime = std::distance(start, it) + 1; |
auto prime = std::distance(start, it) + 1; |
||
// mark all multiples of this prime number as composite. |
// mark all multiples of this prime number as composite. |
||
auto multiple_it = it; |
|||
while (std::distance(multiple_it, end) > prime) |
|||
{ |
{ |
||
std::advance( |
std::advance(multiple_it, prime); |
||
* |
*multiple_it = 1; |
||
} |
} |
||
} |
} |