Problem
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?
#include <iostream>
using namespace std;
bool isPrime(int n)
{
if(n < 2) return false;
for(int i = 3; i*i <= n; i+=2)
if(n%i == 0) return false;
return true;
}
int main()
{
int count = 1;
int a = 0;
for (int i = 3; count <= 10000; i+=2)
{
if (isPrime(i))
{
count++;
a = i;
}
}
cout << a << endl;
}