Created
June 13, 2014 18:18
-
-
Save v3n/56ac17bed0ca368bdd76 to your computer and use it in GitHub Desktop.
Solution to Prime Problem I presented at ID Tech Programming Academy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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