借助於sympy.sieve.extend_to_no()方法,我們可以擴展篩網以使其包含第i個質數。注意:如果列表太短,則列表會擴展50%,因此列表的長度可能會比請求的更長。
用法: sieve.extend_to_no(i)
參數:
i - It denotes that the sieve is extended to include the ith prime number.
返回: 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])
相關用法
- Python sympy.csc()用法及代碼示例
- Python sympy.cot()用法及代碼示例
- Python sympy.nP()用法及代碼示例
- Python sympy.crt()用法及代碼示例
- Python sympy.det()用法及代碼示例
- Python sympy.nC()用法及代碼示例
- Python sympy.cos()用法及代碼示例
- Python sympy.Pow()用法及代碼示例
- Python sympy.eye()用法及代碼示例
- Python sympy.tan()用法及代碼示例
- Python sympy.ones()用法及代碼示例
- Python sympy.sin()用法及代碼示例
- Python sympy.Add()用法及代碼示例
- Python sympy.S()用法及代碼示例
- Python sympy.has()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 Python sympy | sieve.extend_to_no() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。