Python同情 | sieve.extend() 方法
在sympy.sieve.extend()方法的帮助下,我们可以扩大筛子以覆盖所有小于等于给定自然数的素数。
Syntax: sieve.extend(N)
Parameter:
N – It denotes the number up to which the sieve is extended.
Returns: The function does not return anything.
示例 #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])