What is the fastest integer factorization algorithm?

Pulled directly from my answer to this other question. The method will work, but will be slow. “How big are your numbers?” determines the method to use: Less than 2^16 or so: Lookup table. Less than 2^70 or so: Richard Brent’s modification of Pollard’s rho algorithm. Less than 10^50: Lenstra elliptic curve factorization Less than … Read more

What is the most efficient way of finding all the factors of a number in Python?

from functools import reduce def factors(n): return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))) This will return all of the factors, very quickly, of a number n. Why square root as the upper limit? sqrt(x) * sqrt(x) = x. So if the two factors are the … Read more