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?
In [ ]:
sp=2
cnt = 1
while cnt <= 10001:
primeflag = 0
for j in range(2,sp):
if(sp%j == 0):
primeflag = 1
break;
if(primeflag == 1):
pass
else:
print(cnt ,sp)
cnt = cnt +1
sp =sp+1
Out[ ]:
4
In [ ]:
I got the above algorithm from [StackOverflow](https://stackoverflow.com/questions/40205471/find-the-10001st-prime).
This is coded in python. Why does this work? Let's go through it line by line.
We start with sp=2 because that is the first prime number.
Then we set the code to count primes it flags until it reaches the 10,001th one.
We then increase the value of the sp value and check to see if there is a remainder
when dividing the current sp value by previous primes.
If there is a remainder then the value is saved as a prime,
and the loop repeats until 10,001 are flagged as primes
If there is no remainder the value is tossed out, and a new value is checked by
increasing by 1 and running the loop again.
The program supplies 104743 which is a prime number and is indeed the 10001th prime