Skip to content

Commit 6a49aea

Browse files
committed
Fix ys in Pollard's rho algorithm
Previously ys simply tracked the previous value of y. This doesn't make a lot of sense because it means the final loop, meant to protect against finding multiple factors at once, will only run for one iteration before encountering the known non-1 value for G. In Brent's paper it's set before the size-m loop instead of in its body. This is the more logical location because the final loop is a backtracking step to go over the last m or so values with the more accurage gcd instead of the faster multiplication.
1 parent 8c9448b commit 6a49aea

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Primes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ function pollardfactors!(n::T, h::AbstractDict{K,Int}) where {T<:Integer,K<:Inte
411411
k::K = 0
412412
G = 1
413413
while k < r && G == 1
414+
ys = y
414415
for i in 1:(m > (r - k) ? (r - k) : m)
415-
ys = y
416416
y = y^2 % n
417417
y = (y + c) % n
418418
q = (q * (x > y ? x - y : y - x)) % n

0 commit comments

Comments
 (0)