Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python | simpy.nextprime() method

  • Last Updated : 03 Aug, 2021

In simpy 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
nextprime(7)
nextprime(13)
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
nt.nextprime(30)
nt.nextprime(13)
nt.nextprime(2)

Output: 
 

31
17
3

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!