Its funny you should bring this up. Earlier today I made a similar program, though mine just goes through all numbers upto 1,000,000,000:
#include <iostream>
using namespace std;
int main() {
int ind = 0;
int prime;
int max;
int list[10000000] = {2};
for (int i = 3;i < 1000000000;i++) {
prime = 1;
for (int j = 0; j < ind; j++) {
if ((i%list[j]) == 0) {
prime = 0;
break;
}
}
if (prime == 1) {
ind++;
list[ind] = i;
cout << i << "\n";
}
}
return 0;
}
I had an earlier version that brute forced every number, but I found that only using primes works much faster.