mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
fix/factor ~ fix fault when factoring number composed of a squared factor
This commit is contained in:
parent
8593b4c46c
commit
368f47381b
1 changed files with 9 additions and 3 deletions
|
@ -169,10 +169,16 @@ pub fn factor(num: u64) -> Factors {
|
|||
|
||||
if let Some(divisor) = find_factor(factor) {
|
||||
let mut gcd_queue = Decomposition::one();
|
||||
gcd_queue.add(divisor, exp);
|
||||
gcd_queue.add(factor / divisor, exp);
|
||||
|
||||
let mut non_trivial_gcd = true;
|
||||
let quotient = factor / divisor;
|
||||
if quotient == divisor {
|
||||
gcd_queue.add(divisor, exp + 1);
|
||||
} else {
|
||||
gcd_queue.add(divisor, exp);
|
||||
gcd_queue.add(quotient, exp);
|
||||
}
|
||||
|
||||
let mut non_trivial_gcd = quotient != divisor;
|
||||
while non_trivial_gcd {
|
||||
debug_assert_eq!(factor, gcd_queue.product());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue