📜  Python同情 | sieve.extend() 方法

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

Python同情 | sieve.extend() 方法

sympy.sieve.extend()方法的帮助下,我们可以扩大筛子以覆盖所有小于等于给定自然数的素数。

示例 #1:

# import sympy 
from sympy import sieve
  
# Use sieve.extend() method 
sieve.extend(50) 
prime_list = sieve._list
      
print("Prime Numbers up to 50 : {}".format(prime_list))  

输出:

Prime Numbers up to 50 : array('l', [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47])

示例 #2:

# import sympy 
from sympy import sieve
  
# Use sieve.extend() method 
sieve.extend(100) 
prime_list = sieve._list
      
print("Prime Numbers up to 100 : {}".format(prime_list))  

输出:

Prime Numbers up to 100 : array('l', [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97])