Skip to content

Commit 7cf1f55

Browse files
committed
In sieve example, end iteration sooner
The Sieve algorithm only requires checking all elements up to and including the square root of the maximum prime you're looking for. After that, the remaining elements are guaranteed to be prime.
1 parent e6cfb56 commit 7cf1f55

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libcollections/bitv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//! bv.set(0, false);
3434
//! bv.set(1, false);
3535
//!
36-
//! for i in range(2, max_prime) {
36+
//! for i in iter::range_inclusive(2, (max_prime as f64).sqrt() as uint) {
3737
//! // if i is a prime
3838
//! if bv[i] {
3939
//! // Mark all multiples of i as non-prime (any multiples below i * i

0 commit comments

Comments
 (0)