mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 23:02:38 +00:00
Merge pull request #5892 from kralo/fix-5883
factor: rename input parameter
This commit is contained in:
commit
7fa4b389a9
1 changed files with 8 additions and 9 deletions
|
@ -10,15 +10,14 @@ use std::cmp::{max, min};
|
||||||
|
|
||||||
use crate::numeric::*;
|
use crate::numeric::*;
|
||||||
|
|
||||||
pub(crate) fn find_divisor<A: Arithmetic>(n: A) -> u64 {
|
pub(crate) fn find_divisor<A: Arithmetic>(input: A) -> u64 {
|
||||||
#![allow(clippy::many_single_char_names)]
|
|
||||||
let mut rand = {
|
let mut rand = {
|
||||||
let range = Uniform::new(1, n.modulus());
|
let range = Uniform::new(1, input.modulus());
|
||||||
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
|
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
|
||||||
move || n.to_mod(range.sample(&mut rng))
|
move || input.to_mod(range.sample(&mut rng))
|
||||||
};
|
};
|
||||||
|
|
||||||
let quadratic = |a, b| move |x| n.add(n.mul(a, n.mul(x, x)), b);
|
let quadratic = |a, b| move |x| input.add(input.mul(a, input.mul(x, x)), b);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let f = quadratic(rand(), rand());
|
let f = quadratic(rand(), rand());
|
||||||
|
@ -29,11 +28,11 @@ pub(crate) fn find_divisor<A: Arithmetic>(n: A) -> u64 {
|
||||||
x = f(x);
|
x = f(x);
|
||||||
y = f(f(y));
|
y = f(f(y));
|
||||||
let d = {
|
let d = {
|
||||||
let _x = n.to_u64(x);
|
let _x = input.to_u64(x);
|
||||||
let _y = n.to_u64(y);
|
let _y = input.to_u64(y);
|
||||||
gcd(n.modulus(), max(_x, _y) - min(_x, _y))
|
gcd(input.modulus(), max(_x, _y) - min(_x, _y))
|
||||||
};
|
};
|
||||||
if d == n.modulus() {
|
if d == input.modulus() {
|
||||||
// Failure, retry with a different quadratic
|
// Failure, retry with a different quadratic
|
||||||
break;
|
break;
|
||||||
} else if d > 1 {
|
} else if d > 1 {
|
||||||
|
|
Loading…
Reference in a new issue