diff --git a/rust/prime-factors/Cargo.toml b/rust/prime-factors/Cargo.toml index d624041..44211ce 100644 --- a/rust/prime-factors/Cargo.toml +++ b/rust/prime-factors/Cargo.toml @@ -2,6 +2,3 @@ edition = "2021" name = "prime_factors" version = "1.1.0" - -[dependencies] -bit-set = "0.8.0" diff --git a/rust/prime-factors/src/lib.rs b/rust/prime-factors/src/lib.rs index 06353c8..1aa4c8f 100644 --- a/rust/prime-factors/src/lib.rs +++ b/rust/prime-factors/src/lib.rs @@ -1,17 +1,9 @@ -use ::bit_set::BitSet; - pub fn factors(n: u64) -> Vec { let n = n .try_into() .expect("usize is not large enough to factor a u64"); let bound = isqrt(n); - let mut not_primes = { - // We need to be able to store any integer up to and including the bound. - let capacity = bound + 1; - BitSet::with_capacity(capacity) - }; - let mut factors = { // Worst case number of factors is a power of 2, number of // factors will be the number of bits needed to represent @@ -22,9 +14,6 @@ pub fn factors(n: u64) -> Vec { let mut reduced = n; 'outer: for i in 2..=bound { - if not_primes.contains(i) { - continue; - } while reduced % i == 0 { { let i = i @@ -39,11 +28,6 @@ pub fn factors(n: u64) -> Vec { break 'outer; } } - for j in (i * i..=bound).step_by(i) { - // Ensure we allocated enough capacity for all non-primes. - assert!(j < not_primes.capacity()); - not_primes.insert(j); - } } if reduced > 1 {