📜  Python| sympy.primorial() 方法

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

Python| sympy.primorial() 方法

sympy.primorial()方法的帮助下,我们可以找到前n 个素数(默认)或小于或等于n的素数(当nth=False时)的乘积,其中nnth是该方法的参数。

示例 #1:

# import primorial() method from sympy
from sympy import primorial
  
n = 3
  
# Use primorial() method 
primorial_n = primorial(n) # 2 * 3 * 5
      
print("The product of first {} primes is {}".format(n, primorial_n))

输出:

The product of first 3 primes is 30

示例 #2:

# import primorial() method from sympy
from sympy import primorial
  
n = 10
  
# Use primorial() method 
primorial_n = primorial(n, nth = False) # 2 * 3 * 5 * 7
      
print("The product of primes less than or equal to {} is {}".format(n, primorial_n))          

输出:

The product of primes less than or equal to 10 is 210