Python| sympy.factorint() 方法
借助sympy.factorint()方法,我们可以找到给定整数的因子及其对应的重数。对于小于 2 的输入, factorint()的行为如下:
- – 返回空分解{}。
- – 返回 .
- - 添加先到因数再因数 .
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.
示例 #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}