Python sympy | sieve.extend_to_no() method

With the help of sympy.sieve.extend_to_no() method, we can extend the sieve to include the ith prime number.
Note: The list is extended by 50% if it is too short, so it is likely that it will be longer than requested.

Syntax: sieve.extend_to_no(i)
Parameter:
i – It denotes that the seive is extended to include the ith prime number.
Returns: The method does not return anything.

Example #1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))  

chevron_right


Output:

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])

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))   

chevron_right


Output:

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])


My Personal Notes arrow_drop_up

Coder Machine Learner Social Activist Vocalist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.