当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python sympy.primepi()用法及代码示例


借助于sympy.primepi()方法,我们可以找到小于或等于给定数的质数数。

用法: primepi(n)

参数:
n – 它表示要计算素数计数的数字。


返回值:返回小于或等于n的质数个数。

示例1:

# import primepi() method from sympy 
from sympy import primepi 
  
n = 10
  
# Use primepi() method  
count_primes = primepi(n)  
      
print("The number of prime numbers less than or equal to {} is {}".format(n, count_primes))

输出:

The number of prime numbers less than or equal to 10 is 4

示例2:

# import primepi() method from sympy 
from sympy import primepi 
  
n = 150
  
# Use primepi() method  
count_primes = primepi(n)  
      
print("The number of prime numbers less than or equal to {} is {}".format(n, count_primes))          

输出:

The number of prime numbers less than or equal to 150 is 35


相关用法


注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 Python | sympy.primepi() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。