So, what the HELL is going on here... Here's the deal, I made this to find the highest prime factor of the number n (Yeah, w/e that number is, 600 billion something). The thing is, it will run, then all of a sudden it will stop working. Like I will run it say 10 times or so, then it will continuously keep crashing. Sometimes it will print 1 number, sometimes none, sometimes it will cause a runtime error, sometimes just NOTHING happens, I have no freaking idea what the hell is happening here... Also, if I change the array to type int, then run it, it will cause a crash, but then if I change it back to char it will start working again. Every time these crashes happen if I change it to int, run it, then to char it will magically start working again... My only guess is something weird is happening in memory. But I can't see what's wrong with this. Here's the code!
Note: When it actually did work the answer was correct... What the hell? Ok cheers.Code:#include <iostream> #include <cstdlib> #define uint unsigned long long int #define N 10000 using namespace std; char s[N]; void FillSieve() { int x; int y = 2; int i = 0; for (x = 0; x < N; x++) s[x] = 1; while (y < x) { if (s[y] == 1) { i = y; while ( i < N ) { i+=y; s[i] = 0; } } y++; } } int main() { FillSieve(); uint n = 600851475143; int temp = 0; for (int i = 2; i < N; i++) if (s[i] == 1) if ( !(n % i) ) cout << i << endl; }