📜  Python| sympy.factorint() 方法

📅  最后修改于: 2022-05-13 01:54:34.609000             🧑  作者: Mango

Python| sympy.factorint() 方法

借助sympy.factorint()方法,我们可以找到给定整数的因子及其对应的重数。对于小于 2 的输入, factorint()的行为如下:

  • factorint(1) – 返回空分解{}。
  • factorint(0) – 返回{0:1} .
  • factorint(-n) - 添加-1:1先到因数再因数n .

示例 #1:

# 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))

输出:

Dictionary containing factors of 10125000 
with respective multiplicities : {2: 3, 3: 4, 5: 6}

示例 #2:

# 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))

输出:

Dictionary containing factors of 16848 
with respective multiplicities : {2: 4, 3: 4, 13: 1}