By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?
def isPrime(n): if n < 2: return "Neither prime, nor composite" for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True # returns the nth prime number def nthPrime(n): numberOfPrimes = 0 prime = 1 while numberOfPrimes < n: prime += 1 if isPrime(prime): numberOfPrimes += 1 return prime print(nthPrime(10001))
Programming Problem on Hackerrank.com
By listing the first six prime numbers:2,3,5,7,11 and 13 , we can see that the 6th prime is 13 .
What is the Nth prime number?
First line contains T that denotes the number of test cases. This is followed by T lines, each containing an integer, N.
- 1⩽T⩽ 103
- 1⩽N⩽ 104
Print the required answer for each test case.
2 3 6
The first 10 prime numbers are
we can see that 3rd prime number is 5 and 6th prime number is 13
import math def prime(n,l): x=l[len(l)-1] while len(l)y: count=0 break if x%i==0: count=1 break if count==0: l.append(x) return l t=int(input()) l=[2,3] for i in range(t): n=int(input()) if len(l)