Python| sympy.primeomega() 方法
在sympy.primeomega()方法的帮助下,我们可以计算给定正整数的素数计数重数。例如, primeomega(12) = 3 ,因为12 = 2 2 * 3 1 。因此,质因数的个数 = 质因数的重数之和, 2 + 1 = 3。
Syntax: primeomega(n)
Parameter:
n – It denotes an integer.
Returns: Returns the number of prime factors counting multiplicities for a given positive integer.
示例 #1:
# import primeomega() method from sympy
from sympy.ntheory.factor_ import primeomega
n = 24
# Use primeomega() method
primeomega_n = primeomega(n)
print(" Number of prime factors of {} = {} ".format(n, primeomega_n))
输出:
Number of prime factors of 24 = 4
示例 #2:
# import primeomega() method from sympy
from sympy.ntheory.factor_ import primeomega
n = 120
# Use primeomega() method
primeomega_n = primeomega(n)
print(" Number of prime factors of {} = {} ".format(n, primeomega_n))
输出:
Number of prime factors of 120 = 5