Minor changes to src/num.rs for better clarity

This commit is contained in:
AlekseiVambol
2025-02-11 20:21:00 +02:00
parent d47186b013
commit 66f10fdc6f

View File

@@ -7,7 +7,7 @@ pub fn prime_divisors(mut n: u32) -> Vec<u32> {
return vec![]; return vec![];
} }
let mut p = Vec::with_capacity(n.ilog2() as usize); let mut p = Vec::with_capacity(n.ilog2() as usize);
if n & 1 == 0 { if n % 2 == 0 {
p.push(2); p.push(2);
n >>= n.trailing_zeros(); n >>= n.trailing_zeros();
} }
@@ -30,10 +30,10 @@ pub fn prime_divisors(mut n: u32) -> Vec<u32> {
extract(d, &mut n, &mut p); extract(d, &mut n, &mut p);
b = sqrt(n); b = sqrt(n);
} }
// A trial divisor is either 5 or 6k + 1 or 6k + 5 for // At this point, a trial divisor is either 5 or 6k + 1
// some positive integer k. Therefore, the difference // or 6k + 5 for some positive integer k. Therefore, the
// between the (j + 1)-th and the j-th trial divisor // difference between the (j + 1)-th and the j-th trial
// is 2, if j is odd, and 4 otherwise // divisor is 2, if j is odd, and 4 otherwise
(d, s) = (d + s, s ^ 6); (d, s) = (d + s, s ^ 6);
} }
if n > 1 { if n > 1 {