Commit 7fe87f74 by Andrew Dahl

Solved Problem 7

parent 00b91fe9
Showing with 40 additions and 0 deletions
Question:
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?
Answer: 104743
#include <iostream>
#include <vector>
using namespace std;
int main() {
bool is_prime = true;
int max = 10001;
vector<long int> primes;
primes.push_back(2);
primes.push_back(3);
for(long int i = 5; true; i+=2)
{
is_prime = true;
for(int j = 0; j < primes.size(); j++)
{
if(i % primes[j] == 0)
is_prime = false;
}
if(is_prime)
primes.push_back(i);
if((primes.size()) == max)
{
cout << i << endl;
break;
}
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment