Python同情 | sieve.extend_to_no() 方法
借助sympy.sieve.extend_to_no()方法,我们可以扩展筛子以包含第i 个素数。
注意:如果列表太短,将延长 50%,因此很可能会比要求的长。
Syntax: sieve.extend_to_no(i)
Parameter:
i – It denotes that the sieve is extended to include the ith prime number.
Returns: The method does not return anything.
示例 #1:
# import sympy
from sympy import sieve
# Use sieve.extend_to_no() method
sieve.extend_to_no(15)
prime_list = sieve._list
print("Prime Numbers up to 15th prime : {}".format(prime_list))
输出:
Prime Numbers up to 15th prime : array('l', [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61])
示例 #2:
# import sympy
from sympy import sieve
# Use sieve.extend_to_no() method
sieve.extend_to_no(20)
prime_list = sieve._list
print("Prime Numbers up to 15th prime : {}".format(prime_list))
输出:
Prime Numbers up to 15th prime : 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])