All pastes #610061 Raw Edit

Someone

public text v1 · immutable
·published 2007-07-09 07:11 UTC
rendered paste body

//Sum of first million primes
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

vector<int> ps;

void main(){
	
	ps = vector<int>();
	ps.push_back(2);

	double long s = 2;

	for(int i = 3; i < 1000000; i+=2) {
		bool p = true;
		float sp = sqrt(i)+1;
		for(int j = 0; j < ps.size() && ps[j] < sp; j++) {
			if (i % ps[j] == 0) { p = false; break; }
		}
		if (p) {
			ps.push_back(i);
			s += i;
		}
		if ((i-1)%10000==0) cout << "At: " << (i-1) << ", " << ps.size() << endl;
	}

	cout << fixed << s << "," << ps.size() << endl;
}