diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index c43319942fb..e72b6dc01d1 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -2951,13 +2951,21 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): return n - def prime_divisors(self): + def prime_divisors(self, *args, **kwds): """ Return the prime divisors of this integer, sorted in increasing order. If this integer is negative, we do *not* include -1 among its prime divisors, since -1 is not a prime number. + INPUT: + + - ``limit`` -- (integer, optional keyword argument) + Return only prime divisors up to this bound, and the factorization + is done by checking primes up to ``limit`` using trial division. + + Any additional arguments are passed on to the :meth:`factor` method. + EXAMPLES:: sage: a = 1; a.prime_divisors() @@ -2968,8 +2976,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): [2, 5] sage: a = 2004; a.prime_divisors() [2, 3, 167] + + Setting the optional ``limit`` argument works as expected:: + + sage: a = 10^100 + 1 + sage: a.prime_divisors() + [73, 137, 401, 1201, 1601, 1676321, 5964848081, + 129694419029057750551385771184564274499075700947656757821537291527196801] + sage: a.prime_divisors(limit=10^3) + [73, 137, 401] + sage: a.prime_divisors(limit=10^7) + [73, 137, 401, 1201, 1601, 1676321] """ - return [r[0] for r in self.factor()] + res = [r[0] for r in self.factor(*args, **kwds)] + limit = kwds.get('limit') + if limit is not None: + res = [r for r in res if r <= limit] + return res prime_factors = prime_divisors