Skip to content

Instantly share code, notes, and snippets.

@v3n
Created June 13, 2014 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v3n/56ac17bed0ca368bdd76 to your computer and use it in GitHub Desktop.
Save v3n/56ac17bed0ca368bdd76 to your computer and use it in GitHub Desktop.
Solution to Prime Problem I presented at ID Tech Programming Academy
#include <iostream>
#include <vector>
using namespace std;
int i;
unsigned total;
vector<int> v = vector<int>();
vector<int>::iterator vi;
int main(int argc, char const *argv[])
{
cout << sizeof(int) << endl << sizeof(unsigned) << endl;
cout << "Solving problem: ";
v.push_back(2);
i = 3;
total = 0;
for( ; ; ) {
for(vi = v.begin(); vi != v.end(); vi++) {
if ((i % *vi) == 0)
goto skip;
}
v.push_back(i);
// cout << i << endl;
total += i;
if (i == 225287) {
cout << total << endl;
cout << v[v.size() - 1] << endl;
return 0;
}
i++;
continue;
skip:
i++;
continue;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment