How to get prime numbers quickly in python using library functions ?
Library functions always makes our code easy so here we are going to discuss some library function in python to work upon prime numbers. SymPy is a python module which contains some really cool prime number related library functions. Given below is the list of these functions :
- isprime(n) : It tests if n is a prime number (True) or not (False).
- primerange(a, b) : It generates a list of all prime numbers in the range [a, b).
- randprime(a, b) : It returns a random prime number in the range [a, b).
- primepi(n) : It returns the number of prime numbers less than or equal to n.
- prime(nth) : It returns the nth prime, with the primes indexed as prime(1) = 2. The nth prime is approximately n*log(n) and can never be larger than 2**n.
- prevprime(n) : It returns the prev prime smaller than n.
- nextprime(n) : It returns the next greater prime than n.
- sieve.primerange(a, b) : It generates all prime numbers in the range [a, b), implemented as a dynamically growing sieve of Eratosthenes.
This article is contributed by Shashank Mishra (Gullu). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Python | sympy.prime() method
- Mathematical Functions in Python | Set 2 (Logarithmic and Power Functions)
- Mathematical Functions in Python | Set 3 (Trigonometric and Angular Functions)
- Mathematical Functions in Python | Set 4 (Special Functions and Constants)
- Mathematical Functions in Python | Set 1 (Numeric Functions)
- Python | sympy.Add() method
- Python | sympy.Mul() method
- Python | sympy.csc() method
- Python | sympy.cot() method
- Python | sympy RGS method
- Python | sympy.Pow() method
- Python | sympy.crt() method
- Python | sympy.S.GoldenRatio
- Python | sympy.det() method
- Python | sympy.tan() method