Python | sympy.primefactors() method
With the help of sympy.primefactors() method, we can find the prime factors of a given number. Unlike factorint(), primefactors() does not return -1 or 0.
Syntax: primefactors(n) Parameter: n – It denotes an integer. Returns: Returns a list of prime factors of the given integer.
Example #1:
Python3
from sympy import primefactors
n = 2772
primefactors_n = primefactors(n)
print ( "The prime factors of {} : {}" . format (n, primefactors_n))
|
Output:
The prime factors of 2772 : [2, 3, 7, 11]
Example #2:
Python3
from sympy import primefactors
n = - 210
primefactors_n = primefactors(n)
print ( "The prime factors of {} : {}" . format (n, primefactors_n))
|
Output:
The prime factors of -210 : [2, 3, 5, 7]
Last Updated :
30 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...