10001st prime | Project Euler | Problem #7
URL to the problem page: https://projecteuler.net/problem=7
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?
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;
int main()
{
long long a = 0, counter, i, j;
for (i = 2; ; i++) {
counter = 0;
for (j = 2; j <= sqrt(i); j++) {
if (i % j == 0) {
counter++;
break;
}
}
if (counter == 0) {
a++;
if (a == 10001) {
cout << "10 001st prime number is = " << i << endl;
break;
}
}
}
return 0;
Comments
Post a Comment