find all multiplicands and multipliers for a number
no.email at nospam.invalid
Sun Apr 12 19:20:41 CEST 2015
Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:
> Um, "simple sieve"? You're using Miller-Rabin to check for candidate
> prime factors. I don't think that counts as a simple sieve :-)
How does Miller-Rabin help? It has to cost more than trial division.
Meanwhile, trial division up to 100000 is almost instantaneous and gives
[3, 3, 1777, 3331, 17539, 2778562183799360736577L]
where the last factor is composite.
def g(x): return (x*x+1) % n
x = y = 2
x,y = g(x), g(g(y))
d = gcd(abs(x-y), n)
if d != 1:
finds the factor 25781083 almost instantly.
Verifying that 25781083 and the remaining factor is prime, and patching
all the code together to factorize in one operation, is left as an
Note that the Pollard routine is not guaranteed to find a nontrivial
factor. If it fails, try a starting value other than 2. This is also
left as an exercise.
More information about the Python-list