Skip to content

Commit ffb0243

Browse files
authored
Merge pull request cheran-senthil#98 from cheran-senthil/fix/pollard-rho
Vary f to not hang on 124376107291
2 parents bff505b + ea33fd8 commit ffb0243

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pyrival/algebra/factors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def pollard_rho(n):
4040
break
4141
else:
4242
for i in range(2, n):
43-
x, y = i, (i * i + 1) % n
43+
x, y = i, (i * i + i) % n
4444
f = gcd(abs(x - y), n)
4545
while f == 1:
46-
x, y = (x * x + 1) % n, (y * y + 1) % n
47-
y = (y * y + 1) % n
46+
x, y = (x * x + i) % n, (y * y + i) % n
47+
y = (y * y + i) % n
4848
f = gcd(abs(x - y), n)
4949
if f != n:
5050
return f

pyrival/algebra/primitive_root.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def pollard_rho(n):
4040
break
4141
else:
4242
for i in range(2, n):
43-
x, y = i, (i * i + 1) % n
43+
x, y = i, (i * i + i) % n
4444
f = gcd(abs(x - y), n)
4545
while f == 1:
46-
x, y = (x * x + 1) % n, (y * y + 1) % n
47-
y = (y * y + 1) % n
46+
x, y = (x * x + i) % n, (y * y + i) % n
47+
y = (y * y + i) % n
4848
f = gcd(abs(x - y), n)
4949
if f != n:
5050
return f

0 commit comments

Comments
 (0)