[issue40028] Math module method to find prime factors for non-negative int n

Steven D'Aprano report at bugs.python.org
Sat Mar 21 10:25:26 EDT 2020


Steven D'Aprano <steve+python at pearwood.info> added the comment:

Ross: 

"implement this logic for a limited range of non-negative n, imposing an upper limit (suggestions welcome) to make sure all provided input can be safely processed. We can then build from there to support larger n going forward if the demand is out there."

Urgh, please no! Arbitrary limits are horrible. Whatever maximum limit N you guess, somebody will want to factorise N+1. Consider this evidence of demand :-)

On what basis would you choose that limit? Basing it on the size of n is the wrong answer: factorising 2**10000000 is easy, and will be found by trial division almost instantly, even though it's a large number with over three million digits.

Another question: since factorization can take a long time, should it be a generator that yields the factors as they are found?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40028>
_______________________________________


More information about the Python-bugs-list mailing list