Find the 10001st Prime Number in Python | Efficient Code
This Snippet is coded by a user inOnline python Compiler. You can see and run this code too.
زبان: python
This Python code provides a function to check primality and then find the nth prime number. By calling nthPrime(10001), it outputs the desired prime.
How to use: Call the nthPrime(n) function with your desired n. For instance, print(nthPrime(10)) returns the 10th prime.
- The
isPrimefunction checks if a number is prime. - The
nthPrimefunction loops until it finds the nth prime. - Optimized time complexity by checking up to the square root.