Quick actions

cmd+k|ctrl+k

Navigation

Languages

Calculate primes w/ Vector

Snippet info

Language

Cpp

Visibility

public

Author

eduardobilk

Created

2016-04-25T17:24:15Z

Updated

2016-04-25T17:24:35Z

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    std::vector<int> primes;
    primes.push_back(2);
    for(int i=3; i < 30000; i++)
    {
        bool prime=true;
        for(int j=0;j<primes.size() && primes[j]*primes[j] <= i;j++)
        {
            if(i % primes[j] == 0)
            {
                prime=false;
                break;
            }
        }
        if(prime) 
        {
            primes.push_back(i);
            cout << i << " ";
        }
    }
    return 0;
}
INFO