Project Euler Problem7

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 <bits/stdc++.h>
using namespace std;
int main()
{
        int sieve[1000001];

    sieve[0] = 0;
    sieve[1] = 0;


       for(int k=2; k <= 1000000; k++)
       {
           sieve[k] = 1;
       }


    for(int i = 2;i<=1000000;i++)
    {
        if(sieve[i]==1)
        {
            for(int j = 2*i;j<=1000000;j+=i)
            {
                sieve[j] = 0;
            }
        }
    }


    int count = 0;
    for(int i=2; i<=1000000; i++)
    {
        if(sieve[i] == 1)
        {
            count++;
        }
            if(count == 10001)
            {
            cout << i <<"\n";
                    break;
            }
    }
}

Comments

Popular posts from this blog

Project Euler Problem9

Project Euler Problem8