Python | simpy.nextprime() method
Last Updated :
09 Feb, 2023
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
from sympy import *
print (nextprime( 7 ))
print (nextprime( 13 ))
print (nextprime( 2 ))
|
Output:
11
17
3
Code #2:
Python3
import sympy.ntheory as nt
print (nt.nextprime( 30 ))
print (nt.nextprime( 13 ))
print (nt.nextprime( 2 ))
|
Output:
31
17
3
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...