Ian Dorian Macleod
Problem 10
Problem Statement

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

url: https://projecteuler.net/problem=10
Approach

C++ implementation

#include <stdc++.h> 
using namespace std;

vector sieve(int n) {
    vector tmp (n + 1);
    for(int i = 0; i < tmp.size(); i++) {
        tmp[i] = 1;
    }
    for(int i = 2; i <= n; i++) {
        for(int j = i; j <= n; j+=i) {
            if (j != i) {
                tmp[j] = 0;
            }
        }
    }
    vector primes;
    for (int i = 0; i < tmp.size(); i++) {
        if (tmp[i] == 1) 
            primes.push_back(i);
    }
    return primes;
}

int main() {

    long long int res = -1;
    vector primes = sieve(2000000);
    for(auto& x : primes) 
        res += x;
    cout << res << endl;
    return 0;
}
You can also download the source code for this problem here and compile it on your local machine.
Further Analysis