Python sympy.primomega()方法
在sympy.primomega()方法的帮助下,我们可以计算出一个给定的正整数的质因数的数量。例如, primeomega(12) = 3 ,因为12 = 2 2 * 3 1 。因此,质因数的数量=质因数的倍数之和,2+1=3。
语法: primeomega(n)
参数 :
n –它表示一个整数。
返回:返回给定正整数的质因数计数乘数的数量。
示例 #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