Python同情 | sieve.search() 方法
在sympy.sieve.search()方法的帮助下,我们可以找到限制给定数字的素数的索引i、j 。如果给定的数字是素数,则i == j 。
Syntax: sieve.search(n)
Parameter:
n – It denotes the number whose bounding prime indices is found.
Returns: Returns a tuple containing the bounding prime indices of n.
示例 #1:
# import sympy
from sympy import sieve
# Use sieve.search() method
i, j = sieve.search(23)
print("The bounding prime indices of the number 23 : {}, {}".format(i, j))
输出:
The bounding prime indices of the number 23 : 9, 9
示例 #2:
# import sympy
from sympy import sieve
# Use sieve.search() method
i, j = sieve.search(25)
print("The bounding prime indices of the number 23 : {}, {}".format(i, j))
输出:
The bounding prime indices of the number 23 : 9, 10