Saturday, September 21, 2024
Google search engine
HomeLanguagesPython | simpy.nextprime() method

Python | simpy.nextprime() method

In the sympy module, we can get the next prime number for a given number n using sympy.nextprime() function. For n < 2^64 the answer is definitive; larger n values have a small probability of actually being pseudoprimes. 

Syntax:  sympy.nextprime()
Parameter:  n; number to be tested
Return:  next prime value

Code #1: 

Python3




# Python program to get next prime number
# using sympy.nextprime() method
 
# importing sympy module
from sympy import *
 
# calling nextprime function on different numbers
print(nextprime(7))
print(nextprime(13))
print(nextprime(2))


Output: 

11
17
3

Code #2:  

Python3




# Python program to check prime number
# using sympy.isprime() method
 
# importing sympy module
import sympy.ntheory as nt
 
# calling isprime function on different numbers
print(nt.nextprime(30))
print(nt.nextprime(13))
print(nt.nextprime(2))


Output: 

31
17
3
RELATED ARTICLES

Most Popular

Recent Comments