Open In App

Python | sympy.factorint() method

Last Updated : 05 Sep, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
With the help of sympy.factorint() method, we can find the factors and their corresponding multiplicities of a given integer. For input less than 2, factorint() behaves as follows:
  • factorint(1) - returns the empty factorization {}.
  • factorint(0) - returns {0:1}.
  • factorint(-n) - adds -1:1 to the factors and then factors n.
Syntax: factorint(n) Parameter: n - It denotes an integer. Returns: Returns a dictionary containing the prime factors of n as keys and their respective multiplicities as values.
Example #1: Python3
# import factorint() method from sympy
from sympy import factorint

n = 2**3 * 3**4 * 5**6

# Use factorint() method 
factor_dict = factorint(n) 
    
print("Dictionary containing factors of {} with respective multiplicities : {}".
      format(n, factor_dict))
Output:
Dictionary containing factors of 10125000 
with respective multiplicities : {2: 3, 3: 4, 5: 6}
Example #2: Python3
# import factorint() method from sympy
from sympy import factorint

n = 6**4 * 13

# Use factorint() method 
factor_dict = factorint(n) 
    
print("Dictionary containing factors of {} with respective multiplicities : {}".
      format(n, factor_dict))
Output:
Dictionary containing factors of 16848 
with respective multiplicities : {2: 4, 3: 4, 13: 1}

Next Article
Article Tags :
Practice Tags :

Similar Reads