Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/sage/rings/integer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down